This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE
parameter was added to the code chunk to prevent printing of the R code that generated the plot.
#Carga libreria
library(fdth)
## Warning: package 'fdth' was built under R version 4.0.3
##
## Attaching package: 'fdth'
## The following objects are masked from 'package:stats':
##
## sd, var
#Crear bd de datos llamado personas
#a.Crear 100 nombres a partir de 20 nombres (nombres)
#b.Crear aleatorio el género entre Femenino y Masculino (generos)
#c.Crear la edad aleatorio entre 15 y 60 (edades)
#d.Crear el deporte favorito de cada persona aleatorio entre 10 (deportes)
losnombres = c("JORGE","ROBERTO","DIAZ","ISAIAS","GABRIEL","JOSSELIN","RICARDO","NATALIA","VIRIDIANA","JUAN","CARMELO","ANGELICA","CAROLINA","JOEL","DANIELA","KARINA","JESUS","CESAR","LETICIA","EVELYN")
nombres = sample(losnombres,100,replace = TRUE)
nombres
## [1] "GABRIEL" "DANIELA" "CESAR" "JUAN" "JOSSELIN" "RICARDO"
## [7] "DANIELA" "CAROLINA" "NATALIA" "NATALIA" "DIAZ" "CAROLINA"
## [13] "CARMELO" "CARMELO" "LETICIA" "ANGELICA" "LETICIA" "CESAR"
## [19] "DANIELA" "ROBERTO" "ANGELICA" "CAROLINA" "ISAIAS" "JUAN"
## [25] "VIRIDIANA" "JESUS" "JORGE" "CAROLINA" "VIRIDIANA" "DANIELA"
## [31] "CARMELO" "NATALIA" "ISAIAS" "JOEL" "JESUS" "JESUS"
## [37] "KARINA" "JORGE" "ANGELICA" "JOEL" "CAROLINA" "JOEL"
## [43] "DIAZ" "KARINA" "CAROLINA" "DANIELA" "RICARDO" "ANGELICA"
## [49] "ANGELICA" "DIAZ" "DIAZ" "ROBERTO" "GABRIEL" "ISAIAS"
## [55] "CESAR" "LETICIA" "ISAIAS" "GABRIEL" "JUAN" "LETICIA"
## [61] "JESUS" "KARINA" "NATALIA" "JOEL" "JUAN" "JESUS"
## [67] "DANIELA" "GABRIEL" "LETICIA" "DANIELA" "JUAN" "JESUS"
## [73] "DANIELA" "DIAZ" "ROBERTO" "GABRIEL" "EVELYN" "JUAN"
## [79] "DIAZ" "NATALIA" "KARINA" "ROBERTO" "GABRIEL" "VIRIDIANA"
## [85] "JOSSELIN" "JORGE" "CESAR" "CESAR" "VIRIDIANA" "LETICIA"
## [91] "JESUS" "ROBERTO" "VIRIDIANA" "VIRIDIANA" "CAROLINA" "CARMELO"
## [97] "EVELYN" "DANIELA" "VIRIDIANA" "ROBERTO"
generos = sample(c("Femenino","Masculino"), 100, replace = TRUE)
edades = sample(15:60, 100 ,replace = TRUE)
misdeportes = c("FUTBOL","HOCKEY","TENIS","BEISBOL","NATACIÓN","BOX","MMA","TAE KWONDO","ATLETISMO","FUTBOL AMERICANO","VOLLEYBOL")
deportes = sample(misdeportes, 100, replace = TRUE)
personal = data.frame(nombres,generos,edades,deportes)
#Crear tabla de frecuencias
#transform(table(personal$nombres))
tabla_frec.nombres = data.frame(transform(table(personal$nombres)))
names(tabla_frec.nombres) =c("nombres","freq")
tabla_frec.nombres
## nombres freq
## 1 ANGELICA 5
## 2 CARMELO 4
## 3 CAROLINA 7
## 4 CESAR 5
## 5 DANIELA 9
## 6 DIAZ 6
## 7 EVELYN 2
## 8 GABRIEL 6
## 9 ISAIAS 4
## 10 JESUS 7
## 11 JOEL 4
## 12 JORGE 3
## 13 JOSSELIN 2
## 14 JUAN 6
## 15 KARINA 4
## 16 LETICIA 6
## 17 NATALIA 5
## 18 RICARDO 2
## 19 ROBERTO 6
## 20 VIRIDIANA 7
#Elementos N
N = nrow(personal)
N
## [1] 100
#Determinar la frecuencia
freq.r = tabla_frec.nombres$freq / N
freq.r
## [1] 0.05 0.04 0.07 0.05 0.09 0.06 0.02 0.06 0.04 0.07 0.04 0.03 0.02 0.06 0.04
## [16] 0.06 0.05 0.02 0.06 0.07
#Frecuencia porcentual
freq.p = freq.r * 100
freq.p
## [1] 5 4 7 5 9 6 2 6 4 7 4 3 2 6 4 6 5 2 6 7
# Tabla de distribucion
tabla_frec.nombres = cbind(tabla_frec.nombres, freq.r, freq.p)
tabla_frec.nombres
## nombres freq freq.r freq.p
## 1 ANGELICA 5 0.05 5
## 2 CARMELO 4 0.04 4
## 3 CAROLINA 7 0.07 7
## 4 CESAR 5 0.05 5
## 5 DANIELA 9 0.09 9
## 6 DIAZ 6 0.06 6
## 7 EVELYN 2 0.02 2
## 8 GABRIEL 6 0.06 6
## 9 ISAIAS 4 0.04 4
## 10 JESUS 7 0.07 7
## 11 JOEL 4 0.04 4
## 12 JORGE 3 0.03 3
## 13 JOSSELIN 2 0.02 2
## 14 JUAN 6 0.06 6
## 15 KARINA 4 0.04 4
## 16 LETICIA 6 0.06 6
## 17 NATALIA 5 0.05 5
## 18 RICARDO 2 0.02 2
## 19 ROBERTO 6 0.06 6
## 20 VIRIDIANA 7 0.07 7
#Crear tabla de frecuencias con nombres
tabla_frec.nombres.2 = data.frame(fdt_cat(personal$nombres))
names(tabla_frec.nombres.2) = c('nombres', 'freq', 'freq.r', 'freq.p', 'freq.acum', 'frec.por.acum')
tabla_frec.nombres.2
## nombres freq freq.r freq.p freq.acum frec.por.acum
## 1 DANIELA 9 0.09 9 9 9
## 2 CAROLINA 7 0.07 7 16 16
## 3 JESUS 7 0.07 7 23 23
## 4 VIRIDIANA 7 0.07 7 30 30
## 5 DIAZ 6 0.06 6 36 36
## 6 GABRIEL 6 0.06 6 42 42
## 7 JUAN 6 0.06 6 48 48
## 8 LETICIA 6 0.06 6 54 54
## 9 ROBERTO 6 0.06 6 60 60
## 10 ANGELICA 5 0.05 5 65 65
## 11 CESAR 5 0.05 5 70 70
## 12 NATALIA 5 0.05 5 75 75
## 13 CARMELO 4 0.04 4 79 79
## 14 ISAIAS 4 0.04 4 83 83
## 15 JOEL 4 0.04 4 87 87
## 16 KARINA 4 0.04 4 91 91
## 17 JORGE 3 0.03 3 94 94
## 18 EVELYN 2 0.02 2 96 96
## 19 JOSSELIN 2 0.02 2 98 98
## 20 RICARDO 2 0.02 2 100 100
#Tabla de frecuencias de nombres
barplot(height = tabla_frec.nombres.2$freq, names.arg = tabla_frec.nombres.2$nombres)
#Tabla de edades
hist(personal$edades, main = "Frecuencia de edades", xlab = "Edades", ylab = "Frecuencias")
#Edades en orden
tabla.frec.edades = data.frame(transform(table(personal$edades)))
# tabla.frecuencias.edades
names(tabla.frec.edades) = c("edades", "freq")
tabla.frec.edades
## edades freq
## 1 15 2
## 2 16 4
## 3 17 2
## 4 18 2
## 5 19 1
## 6 20 2
## 7 21 3
## 8 22 2
## 9 24 4
## 10 25 3
## 11 26 2
## 12 27 5
## 13 28 1
## 14 29 4
## 15 30 3
## 16 31 2
## 17 33 5
## 18 34 3
## 19 35 2
## 20 36 6
## 21 37 1
## 22 38 1
## 23 39 3
## 24 40 3
## 25 41 5
## 26 42 2
## 27 43 4
## 28 44 1
## 29 45 2
## 30 47 3
## 31 50 1
## 32 51 1
## 33 52 1
## 34 53 3
## 35 54 3
## 36 55 1
## 37 56 1
## 38 57 1
## 39 59 4
## 40 60 1
#Frecuencia edades
tabla.frec.edades_2 = fdt(personal$edades)
tabla.frec.edades_2 = data.frame(tabla.frec.edades_2$table)
names(tabla.frec.edades_2) = c('clases', 'freq', 'freq.r', 'freq.p', 'freq.acum', 'frec.por.acum')
tabla.frec.edades_2
## clases freq freq.r freq.p freq.acum frec.por.acum
## 1 [14.85,20.57) 13 0.13 13 13 13
## 2 [20.57,26.29) 14 0.14 14 27 27
## 3 [26.29,32.01) 15 0.15 15 42 42
## 4 [32.01,37.73) 17 0.17 17 59 59
## 5 [37.73,43.44) 18 0.18 18 77 77
## 6 [43.44,49.16) 6 0.06 6 83 83
## 7 [49.16,54.88) 9 0.09 9 92 92
## 8 [54.88,60.6) 8 0.08 8 100 100
#Barras edades
barplot(height = tabla.frec.edades_2$freq,
names.arg = tabla.frec.edades_2$clases,
main = "Frecuencias de Clases",
xlab = "Clases de edades", ylab = "Frecuencias")
#Tabla Genero
tabla_frec.genero = data.frame(fdt_cat(personal$generos))
names(tabla_frec.genero) = c('generos', 'freq', 'freq.r', 'freq.p', 'freq.acum', 'frec.por.acum')
tabla_frec.genero
## generos freq freq.r freq.p freq.acum frec.por.acum
## 1 Femenino 51 0.51 51 51 51
## 2 Masculino 49 0.49 49 100 100
#Barras Gnero
barplot(height = tabla_frec.genero$freq,
names.arg = tabla_frec.genero$generos,
main = "Frecuencias de Géneros",
xlab = "Géneros", ylab = "Frecuencias")
#Tabla deporte
tabla_frec.deporte = data.frame(fdt_cat(personal$deportes))
names(tabla_frec.deporte) = c('deportes', 'freq', 'freq.r', 'freq.p', 'freq.acum', 'frec.por.acum')
tabla_frec.deporte
## deportes freq freq.r freq.p freq.acum frec.por.acum
## 1 VOLLEYBOL 14 0.14 14 14 14
## 2 BEISBOL 13 0.13 13 27 27
## 3 ATLETISMO 10 0.10 10 37 37
## 4 FUTBOL 10 0.10 10 47 47
## 5 HOCKEY 10 0.10 10 57 57
## 6 BOX 8 0.08 8 65 65
## 7 MMA 8 0.08 8 73 73
## 8 TAE KWONDO 8 0.08 8 81 81
## 9 NATACIÓN 7 0.07 7 88 88
## 10 TENIS 7 0.07 7 95 95
## 11 FUTBOL AMERICANO 5 0.05 5 100 100
#BARRA DEPORTE
barplot(height = tabla_frec.deporte$freq,
names.arg = tabla_frec.deporte$deportes,
main = "Frecuencias de deportes",
xlab = "Deportes", ylab = "Frecuencias")