sim_lanza=function(){
dado1=1:6
dado2=1:6
x=sample(dado1,1)+sample(dado2,1)
return(x)
}
sim_lanza()
## [1] 2
Opción 1
simula_multi_lanza=function(nlanza,valor_condi){
lanzamientos=array(NA,nlanza)
for(i in 1:nlanza){
lanzamientos[i]=sim_lanza()
}
return(sum(lanzamientos==valor_condi))
}
simula_multi_lanza(nlanza = 500,valor_condi = 7)
## [1] 98
Opción 2
sim_multi_lanza2=function(n_lanza,valor_condi){
dado1=1:6
dado2=1:6
x=sample(dado1,size = n_lanza,replace = TRUE)+sample(dado2,size = n_lanza,replace = TRUE)
return(sum(x==valor_condi))
}
sim_multi_lanza2(n_lanza = 500,valor_condi = 7)
## [1] 80
Probabilidad Teórica (combinaciones)
dado1=1:6
dado2=1:6
espacio=expand.grid(dado1,dado2)
y=apply(espacio,1,sum)
data.frame(espacio,y)
prob_teorica=table(y)/36
prob_teorica
## y
## 2 3 4 5 6 7 8
## 0.02777778 0.05555556 0.08333333 0.11111111 0.13888889 0.16666667 0.13888889
## 9 10 11 12
## 0.11111111 0.08333333 0.05555556 0.02777778
plot(2:12,prob_teorica,type = "b")
Via Simulación cual es el valor aproximado de la probabilidad
sim_multi_lanza2(n_lanza = 1000000,valor_condi = 2)/1000000
## [1] 0.027824
sim_multi_lanza2(n_lanza = 1000000,valor_condi = 7)/1000000
## [1] 0.166812
#sim_multi_lanza2(n_lanza = 1000000,valor_condi = 2)/1000000
sim_multi_lanza2(n_lanza = 1000000,valor_condi = 7)/1000000
## [1] 0.166501
pob=c(rep(x = 1,100),rep(x = 0,900))
sum(sample(pob,size = 200))/200
## [1] 0.09
Opción 1
porcentajes_muestra=array(NA,1000)
for(i in 1:1000){
pob=c(rep(x = 1,100),rep(x = 0,900))
porcentajes_muestra[i]=sum(sample(pob,size = 200))/200
}
porcentajes_muestra
## [1] 0.095 0.115 0.130 0.090 0.115 0.110 0.075 0.120 0.080 0.115 0.085 0.065
## [13] 0.085 0.080 0.115 0.110 0.105 0.090 0.090 0.155 0.095 0.090 0.095 0.120
## [25] 0.130 0.125 0.105 0.130 0.145 0.100 0.070 0.120 0.140 0.095 0.115 0.100
## [37] 0.105 0.080 0.120 0.095 0.120 0.070 0.120 0.090 0.095 0.085 0.090 0.095
## [49] 0.085 0.110 0.060 0.060 0.105 0.050 0.120 0.105 0.065 0.095 0.105 0.095
## [61] 0.120 0.090 0.105 0.120 0.100 0.110 0.140 0.100 0.105 0.080 0.095 0.105
## [73] 0.060 0.095 0.075 0.080 0.135 0.090 0.070 0.090 0.110 0.115 0.125 0.090
## [85] 0.125 0.090 0.140 0.095 0.100 0.130 0.100 0.130 0.125 0.105 0.160 0.075
## [97] 0.130 0.070 0.080 0.080 0.080 0.115 0.105 0.080 0.125 0.105 0.115 0.095
## [109] 0.095 0.110 0.090 0.130 0.120 0.105 0.090 0.090 0.090 0.120 0.080 0.075
## [121] 0.095 0.075 0.110 0.100 0.100 0.075 0.095 0.105 0.090 0.080 0.100 0.105
## [133] 0.115 0.080 0.090 0.100 0.095 0.100 0.130 0.110 0.105 0.110 0.085 0.155
## [145] 0.100 0.110 0.110 0.090 0.100 0.090 0.125 0.060 0.125 0.075 0.110 0.090
## [157] 0.090 0.070 0.080 0.075 0.105 0.105 0.095 0.115 0.075 0.105 0.095 0.110
## [169] 0.060 0.115 0.100 0.085 0.075 0.080 0.095 0.110 0.115 0.085 0.105 0.080
## [181] 0.150 0.090 0.075 0.115 0.100 0.085 0.080 0.095 0.070 0.100 0.105 0.075
## [193] 0.100 0.125 0.115 0.095 0.075 0.075 0.110 0.125 0.100 0.110 0.085 0.095
## [205] 0.070 0.110 0.100 0.090 0.090 0.065 0.075 0.095 0.095 0.120 0.080 0.130
## [217] 0.120 0.100 0.090 0.135 0.095 0.095 0.090 0.080 0.110 0.080 0.085 0.085
## [229] 0.140 0.105 0.050 0.130 0.080 0.105 0.065 0.125 0.100 0.140 0.095 0.110
## [241] 0.075 0.075 0.080 0.100 0.110 0.100 0.100 0.100 0.100 0.075 0.080 0.085
## [253] 0.105 0.150 0.090 0.080 0.110 0.085 0.100 0.115 0.075 0.085 0.085 0.095
## [265] 0.070 0.070 0.095 0.095 0.095 0.100 0.065 0.085 0.095 0.110 0.100 0.080
## [277] 0.140 0.070 0.110 0.110 0.070 0.110 0.075 0.125 0.085 0.090 0.095 0.085
## [289] 0.095 0.125 0.110 0.075 0.115 0.105 0.125 0.095 0.090 0.105 0.145 0.110
## [301] 0.075 0.070 0.090 0.125 0.105 0.130 0.105 0.075 0.085 0.105 0.115 0.095
## [313] 0.110 0.105 0.045 0.115 0.065 0.075 0.090 0.085 0.105 0.110 0.105 0.105
## [325] 0.085 0.125 0.075 0.095 0.085 0.110 0.075 0.110 0.080 0.100 0.075 0.105
## [337] 0.105 0.115 0.085 0.070 0.090 0.085 0.120 0.125 0.105 0.150 0.100 0.115
## [349] 0.080 0.080 0.115 0.115 0.090 0.110 0.095 0.100 0.100 0.095 0.090 0.135
## [361] 0.060 0.130 0.095 0.095 0.090 0.095 0.105 0.110 0.085 0.085 0.105 0.075
## [373] 0.130 0.065 0.105 0.100 0.100 0.115 0.095 0.110 0.095 0.105 0.100 0.115
## [385] 0.110 0.085 0.100 0.065 0.125 0.095 0.095 0.080 0.105 0.140 0.105 0.085
## [397] 0.070 0.070 0.115 0.090 0.120 0.095 0.090 0.095 0.110 0.085 0.100 0.115
## [409] 0.080 0.125 0.110 0.095 0.075 0.150 0.090 0.120 0.105 0.100 0.085 0.115
## [421] 0.130 0.120 0.090 0.130 0.070 0.105 0.090 0.075 0.075 0.100 0.115 0.080
## [433] 0.110 0.110 0.085 0.110 0.105 0.070 0.095 0.105 0.080 0.055 0.120 0.115
## [445] 0.115 0.105 0.120 0.100 0.105 0.085 0.100 0.120 0.065 0.075 0.100 0.115
## [457] 0.090 0.105 0.115 0.125 0.070 0.095 0.115 0.120 0.105 0.080 0.065 0.105
## [469] 0.100 0.065 0.095 0.135 0.100 0.120 0.125 0.105 0.105 0.105 0.125 0.110
## [481] 0.105 0.075 0.135 0.110 0.120 0.080 0.100 0.105 0.065 0.100 0.125 0.080
## [493] 0.105 0.085 0.110 0.115 0.060 0.090 0.095 0.065 0.100 0.095 0.100 0.115
## [505] 0.130 0.095 0.130 0.085 0.120 0.105 0.050 0.100 0.100 0.115 0.090 0.110
## [517] 0.140 0.100 0.100 0.095 0.105 0.100 0.120 0.085 0.150 0.065 0.090 0.095
## [529] 0.070 0.075 0.090 0.110 0.105 0.075 0.085 0.125 0.105 0.070 0.135 0.100
## [541] 0.100 0.080 0.070 0.135 0.125 0.090 0.105 0.115 0.075 0.120 0.100 0.090
## [553] 0.070 0.080 0.110 0.115 0.105 0.105 0.125 0.100 0.090 0.115 0.100 0.100
## [565] 0.085 0.120 0.110 0.100 0.125 0.050 0.090 0.095 0.090 0.090 0.065 0.110
## [577] 0.090 0.110 0.095 0.085 0.105 0.110 0.070 0.090 0.085 0.115 0.095 0.075
## [589] 0.120 0.085 0.100 0.125 0.080 0.085 0.110 0.095 0.105 0.085 0.115 0.155
## [601] 0.120 0.105 0.085 0.085 0.100 0.060 0.110 0.095 0.095 0.085 0.085 0.115
## [613] 0.145 0.085 0.105 0.115 0.080 0.105 0.100 0.090 0.080 0.135 0.085 0.090
## [625] 0.115 0.150 0.110 0.075 0.065 0.100 0.085 0.105 0.090 0.150 0.115 0.080
## [637] 0.095 0.115 0.120 0.100 0.090 0.115 0.125 0.110 0.105 0.075 0.125 0.095
## [649] 0.110 0.115 0.090 0.120 0.075 0.075 0.105 0.090 0.100 0.115 0.115 0.110
## [661] 0.085 0.115 0.095 0.075 0.095 0.100 0.075 0.085 0.110 0.085 0.075 0.105
## [673] 0.075 0.090 0.065 0.120 0.110 0.085 0.120 0.085 0.120 0.065 0.075 0.120
## [685] 0.100 0.090 0.100 0.115 0.115 0.105 0.115 0.115 0.100 0.130 0.110 0.090
## [697] 0.120 0.110 0.105 0.100 0.120 0.085 0.070 0.100 0.100 0.135 0.110 0.080
## [709] 0.100 0.095 0.105 0.125 0.090 0.095 0.115 0.075 0.095 0.100 0.115 0.075
## [721] 0.060 0.105 0.090 0.065 0.055 0.130 0.125 0.125 0.080 0.100 0.080 0.080
## [733] 0.100 0.125 0.115 0.085 0.120 0.080 0.105 0.090 0.090 0.095 0.110 0.085
## [745] 0.085 0.105 0.095 0.115 0.125 0.075 0.080 0.110 0.100 0.100 0.085 0.090
## [757] 0.105 0.105 0.145 0.125 0.075 0.090 0.090 0.115 0.125 0.085 0.125 0.075
## [769] 0.085 0.065 0.085 0.105 0.080 0.100 0.110 0.085 0.090 0.110 0.115 0.110
## [781] 0.100 0.105 0.105 0.105 0.110 0.090 0.125 0.080 0.130 0.105 0.090 0.105
## [793] 0.115 0.095 0.100 0.105 0.100 0.105 0.120 0.105 0.120 0.110 0.100 0.110
## [805] 0.105 0.115 0.090 0.045 0.135 0.110 0.125 0.105 0.060 0.065 0.085 0.100
## [817] 0.100 0.090 0.100 0.100 0.130 0.085 0.095 0.095 0.095 0.105 0.160 0.100
## [829] 0.130 0.090 0.080 0.115 0.110 0.070 0.085 0.075 0.065 0.090 0.110 0.105
## [841] 0.070 0.125 0.100 0.080 0.125 0.115 0.130 0.110 0.095 0.130 0.120 0.110
## [853] 0.120 0.100 0.105 0.105 0.085 0.100 0.120 0.080 0.085 0.095 0.070 0.110
## [865] 0.100 0.100 0.095 0.110 0.085 0.100 0.095 0.120 0.105 0.100 0.110 0.125
## [877] 0.115 0.080 0.110 0.095 0.085 0.085 0.105 0.120 0.100 0.075 0.105 0.115
## [889] 0.110 0.090 0.095 0.125 0.095 0.095 0.095 0.070 0.125 0.110 0.065 0.100
## [901] 0.090 0.100 0.105 0.140 0.080 0.085 0.105 0.085 0.090 0.090 0.100 0.115
## [913] 0.070 0.130 0.110 0.090 0.105 0.090 0.125 0.080 0.095 0.095 0.100 0.110
## [925] 0.130 0.115 0.110 0.100 0.100 0.075 0.105 0.110 0.115 0.080 0.105 0.115
## [937] 0.115 0.090 0.130 0.095 0.090 0.095 0.080 0.115 0.130 0.105 0.100 0.120
## [949] 0.115 0.055 0.105 0.105 0.125 0.085 0.095 0.120 0.125 0.100 0.060 0.080
## [961] 0.105 0.055 0.120 0.065 0.090 0.110 0.120 0.085 0.135 0.100 0.090 0.085
## [973] 0.110 0.075 0.055 0.090 0.075 0.150 0.110 0.095 0.095 0.090 0.090 0.095
## [985] 0.080 0.095 0.080 0.125 0.130 0.105 0.075 0.065 0.125 0.130 0.055 0.085
## [997] 0.115 0.085 0.100 0.080
opción 2 con una Función
calc_por_uno=function(n_muestra){
pob=c(rep(x = 1,100),rep(x = 0,900))
return(sum(sample(pob,size = n_muestra))/n_muestra)
}
calc_por_uno(n_muestra = 200)
## [1] 0.115
sapply(rep(200,1000), calc_por_uno)
## [1] 0.075 0.110 0.080 0.085 0.075 0.105 0.080 0.100 0.140 0.095 0.060 0.080
## [13] 0.120 0.100 0.115 0.100 0.150 0.115 0.100 0.120 0.105 0.105 0.075 0.090
## [25] 0.130 0.090 0.095 0.120 0.130 0.100 0.120 0.105 0.075 0.100 0.135 0.090
## [37] 0.075 0.085 0.075 0.090 0.085 0.075 0.115 0.070 0.090 0.115 0.085 0.085
## [49] 0.095 0.140 0.100 0.075 0.085 0.095 0.100 0.115 0.100 0.100 0.110 0.095
## [61] 0.130 0.110 0.090 0.105 0.110 0.095 0.070 0.100 0.110 0.095 0.050 0.120
## [73] 0.100 0.110 0.145 0.065 0.075 0.115 0.090 0.125 0.085 0.105 0.105 0.130
## [85] 0.075 0.105 0.110 0.130 0.120 0.140 0.145 0.110 0.100 0.095 0.100 0.105
## [97] 0.100 0.130 0.120 0.090 0.100 0.100 0.095 0.145 0.095 0.110 0.080 0.070
## [109] 0.115 0.120 0.075 0.120 0.085 0.085 0.095 0.095 0.105 0.090 0.075 0.085
## [121] 0.090 0.090 0.125 0.095 0.120 0.090 0.090 0.105 0.095 0.115 0.110 0.095
## [133] 0.105 0.070 0.120 0.100 0.115 0.100 0.100 0.115 0.100 0.075 0.080 0.095
## [145] 0.095 0.110 0.085 0.095 0.065 0.105 0.070 0.115 0.110 0.105 0.140 0.105
## [157] 0.100 0.095 0.135 0.085 0.135 0.140 0.105 0.095 0.090 0.080 0.105 0.095
## [169] 0.065 0.080 0.085 0.110 0.120 0.110 0.100 0.060 0.125 0.095 0.115 0.115
## [181] 0.085 0.100 0.110 0.105 0.095 0.100 0.085 0.115 0.095 0.120 0.115 0.105
## [193] 0.105 0.065 0.090 0.100 0.090 0.105 0.110 0.095 0.085 0.080 0.120 0.130
## [205] 0.105 0.095 0.105 0.095 0.100 0.110 0.075 0.085 0.085 0.115 0.120 0.070
## [217] 0.095 0.100 0.090 0.085 0.110 0.105 0.130 0.075 0.105 0.090 0.105 0.100
## [229] 0.065 0.100 0.100 0.110 0.100 0.105 0.090 0.070 0.095 0.085 0.110 0.085
## [241] 0.085 0.070 0.105 0.115 0.080 0.085 0.125 0.085 0.095 0.105 0.120 0.100
## [253] 0.090 0.120 0.085 0.115 0.085 0.105 0.075 0.145 0.115 0.100 0.085 0.130
## [265] 0.080 0.135 0.105 0.095 0.105 0.080 0.090 0.095 0.100 0.120 0.100 0.080
## [277] 0.075 0.090 0.110 0.090 0.085 0.110 0.080 0.130 0.105 0.070 0.070 0.100
## [289] 0.070 0.100 0.135 0.090 0.105 0.090 0.075 0.080 0.075 0.090 0.115 0.075
## [301] 0.100 0.120 0.110 0.070 0.090 0.070 0.120 0.100 0.095 0.105 0.105 0.105
## [313] 0.050 0.090 0.080 0.100 0.120 0.135 0.115 0.110 0.100 0.095 0.130 0.120
## [325] 0.110 0.100 0.095 0.115 0.110 0.110 0.095 0.115 0.070 0.105 0.130 0.080
## [337] 0.095 0.095 0.115 0.115 0.085 0.105 0.110 0.095 0.090 0.115 0.095 0.085
## [349] 0.085 0.120 0.105 0.110 0.105 0.070 0.095 0.110 0.100 0.070 0.080 0.075
## [361] 0.135 0.100 0.080 0.100 0.065 0.095 0.095 0.090 0.095 0.125 0.125 0.105
## [373] 0.080 0.140 0.110 0.060 0.100 0.100 0.135 0.090 0.085 0.085 0.060 0.105
## [385] 0.135 0.095 0.085 0.125 0.095 0.120 0.110 0.110 0.105 0.120 0.120 0.090
## [397] 0.105 0.075 0.110 0.085 0.105 0.110 0.095 0.105 0.085 0.115 0.150 0.095
## [409] 0.090 0.115 0.060 0.090 0.130 0.080 0.075 0.125 0.110 0.110 0.095 0.095
## [421] 0.100 0.080 0.100 0.145 0.110 0.120 0.095 0.130 0.095 0.090 0.095 0.110
## [433] 0.125 0.090 0.120 0.130 0.095 0.120 0.135 0.095 0.115 0.125 0.115 0.110
## [445] 0.095 0.110 0.095 0.085 0.110 0.090 0.075 0.115 0.085 0.085 0.110 0.100
## [457] 0.125 0.125 0.085 0.060 0.095 0.110 0.080 0.120 0.105 0.090 0.085 0.095
## [469] 0.100 0.100 0.095 0.110 0.070 0.105 0.050 0.090 0.120 0.125 0.075 0.075
## [481] 0.110 0.110 0.070 0.110 0.115 0.085 0.115 0.125 0.100 0.075 0.120 0.090
## [493] 0.110 0.090 0.110 0.090 0.125 0.095 0.115 0.095 0.120 0.090 0.095 0.090
## [505] 0.085 0.090 0.115 0.130 0.105 0.135 0.090 0.085 0.085 0.105 0.055 0.080
## [517] 0.110 0.075 0.120 0.090 0.060 0.110 0.095 0.100 0.085 0.075 0.095 0.155
## [529] 0.055 0.110 0.100 0.100 0.105 0.075 0.105 0.105 0.075 0.110 0.095 0.110
## [541] 0.105 0.105 0.105 0.115 0.135 0.090 0.080 0.095 0.105 0.095 0.085 0.100
## [553] 0.075 0.095 0.065 0.140 0.130 0.085 0.115 0.095 0.085 0.085 0.095 0.105
## [565] 0.080 0.095 0.080 0.100 0.115 0.080 0.070 0.080 0.085 0.115 0.065 0.100
## [577] 0.090 0.080 0.090 0.120 0.090 0.075 0.135 0.085 0.095 0.100 0.070 0.090
## [589] 0.090 0.075 0.075 0.070 0.110 0.100 0.110 0.085 0.105 0.115 0.095 0.120
## [601] 0.085 0.090 0.095 0.085 0.095 0.115 0.090 0.080 0.125 0.120 0.115 0.130
## [613] 0.110 0.095 0.080 0.105 0.090 0.070 0.130 0.085 0.090 0.060 0.060 0.085
## [625] 0.100 0.085 0.125 0.100 0.090 0.075 0.120 0.110 0.070 0.100 0.100 0.140
## [637] 0.130 0.120 0.085 0.090 0.100 0.100 0.100 0.105 0.100 0.105 0.105 0.100
## [649] 0.120 0.115 0.115 0.090 0.145 0.105 0.125 0.090 0.105 0.100 0.060 0.085
## [661] 0.090 0.120 0.115 0.080 0.100 0.080 0.090 0.090 0.100 0.105 0.140 0.095
## [673] 0.080 0.125 0.095 0.090 0.090 0.095 0.100 0.080 0.110 0.080 0.085 0.100
## [685] 0.110 0.095 0.105 0.100 0.095 0.075 0.070 0.100 0.085 0.125 0.065 0.110
## [697] 0.115 0.095 0.080 0.085 0.070 0.095 0.105 0.090 0.115 0.100 0.120 0.110
## [709] 0.115 0.100 0.065 0.060 0.075 0.115 0.110 0.080 0.095 0.075 0.070 0.120
## [721] 0.120 0.110 0.130 0.065 0.090 0.070 0.085 0.120 0.135 0.100 0.145 0.100
## [733] 0.085 0.070 0.095 0.085 0.105 0.135 0.100 0.075 0.110 0.060 0.130 0.060
## [745] 0.115 0.110 0.125 0.105 0.085 0.085 0.105 0.075 0.120 0.080 0.100 0.100
## [757] 0.080 0.100 0.115 0.095 0.100 0.100 0.090 0.090 0.085 0.065 0.095 0.090
## [769] 0.100 0.080 0.075 0.115 0.120 0.105 0.130 0.110 0.080 0.120 0.115 0.115
## [781] 0.110 0.060 0.080 0.110 0.140 0.085 0.085 0.105 0.070 0.055 0.115 0.095
## [793] 0.100 0.110 0.090 0.115 0.085 0.100 0.090 0.130 0.105 0.080 0.110 0.075
## [805] 0.115 0.115 0.100 0.100 0.095 0.080 0.075 0.100 0.115 0.080 0.070 0.085
## [817] 0.100 0.145 0.100 0.075 0.070 0.120 0.080 0.075 0.095 0.070 0.125 0.095
## [829] 0.070 0.075 0.065 0.120 0.055 0.125 0.080 0.095 0.100 0.070 0.085 0.110
## [841] 0.110 0.095 0.110 0.105 0.105 0.100 0.110 0.105 0.115 0.075 0.090 0.100
## [853] 0.110 0.120 0.110 0.115 0.090 0.105 0.085 0.090 0.080 0.105 0.130 0.085
## [865] 0.150 0.105 0.100 0.100 0.130 0.100 0.110 0.090 0.090 0.080 0.120 0.095
## [877] 0.085 0.115 0.095 0.105 0.095 0.115 0.125 0.115 0.070 0.100 0.115 0.095
## [889] 0.125 0.080 0.095 0.100 0.090 0.065 0.095 0.100 0.115 0.125 0.130 0.065
## [901] 0.080 0.135 0.090 0.090 0.105 0.035 0.090 0.095 0.095 0.100 0.060 0.110
## [913] 0.085 0.105 0.085 0.100 0.100 0.115 0.110 0.100 0.080 0.100 0.075 0.105
## [925] 0.075 0.090 0.080 0.125 0.090 0.165 0.100 0.125 0.090 0.090 0.095 0.105
## [937] 0.085 0.100 0.070 0.080 0.090 0.140 0.115 0.110 0.110 0.120 0.115 0.105
## [949] 0.100 0.100 0.135 0.100 0.065 0.080 0.100 0.105 0.125 0.090 0.110 0.085
## [961] 0.075 0.095 0.090 0.080 0.095 0.120 0.100 0.140 0.105 0.100 0.080 0.110
## [973] 0.100 0.095 0.105 0.125 0.100 0.145 0.105 0.100 0.120 0.070 0.100 0.100
## [985] 0.125 0.110 0.080 0.120 0.115 0.085 0.110 0.135 0.140 0.100 0.080 0.115
## [997] 0.100 0.060 0.075 0.075
summary(porcentajes_muestra)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.04500 0.08500 0.10000 0.09933 0.11000 0.16000
hist(porcentajes_muestra)
#abline (v=0.05,col="red",lwd=4, lty = 2)
abline (v = mean (porcentajes_muestra), lwd = 4, lty = 1, col="blue")
abline (v=0.05, lwd = 4, lty = 2, col="orange")
names(df)
## [1] "Rotación" "Edad"
## [3] "Viaje de Negocios" "Departamento"
## [5] "Distancia_Casa" "Educación"
## [7] "Campo_Educación" "Satisfacción_Ambiental"
## [9] "Genero" "Cargo"
## [11] "Satisfación_Laboral" "Estado_Civil"
## [13] "Ingreso_Mensual" "Trabajos_Anteriores"
## [15] "Horas_Extra" "Porcentaje_aumento_salarial"
## [17] "Rendimiento_Laboral" "Años_Experiencia"
## [19] "Capacitaciones" "Equilibrio_Trabajo_Vida"
## [21] "Antigüedad" "Antigüedad_Cargo"
## [23] "Años_ultima_promoción" "Años_acargo_con_mismo_jefe"
variable_cuanti <- data.frame("Años_Experiencia" = cbind(sample(x = c(1:40), size = 1000, replace = TRUE)))
funcion = function(df, col){
require(ggplot2)
require(ggpubr)
grafica_1 = ggplot(data = df, mapping = aes(x = df[, col])) + geom_histogram(bins = 40) + labs(x = "Años_Experiencia", y = "Frecuencia")
grafica_2 = ggplot(data = df, mapping = aes(x = df[, col])) + geom_boxplot() + labs(x = "Años_Experiencia")
grafica_3 = ggarrange(grafica_1, grafica_2, ncol = 2, nrow = 1)
summary = summary(df[, col])
grafica_4 = list("Gráficos" = grafica_3, "Resumen" = summary)
return(grafica_4)
}
barplot(table(variable_cuanti),xlab="Años_Experiencia",main="Distribución de Años_Experiencia", col="orange")
boxplot(variable_cuanti, main = "Gráfico de cajas - Años_Experiencia",
outline = TRUE)
summary(variable_cuanti)
## Años_Experiencia
## Min. : 1.00
## 1st Qu.:10.00
## Median :20.00
## Mean :20.32
## 3rd Qu.:30.25
## Max. :40.00
variable_cualit <- data.frame("Estado_Civil" = cbind(sample(x = c("Soltero","Casado","divorsiado"), size = 1000, replace = TRUE)))
funcion_2 = function(df, col){
require(ggplot2)
require(ggpubr)
grafica1 = ggplot(data = df, mapping = aes(x = df[, col])) + geom_histogram(bins = 40) + labs(x = df$Estado_Civil, y = "Frecuencia")
}
barplot(table(variable_cualit), col = c("blue","green","orange"),
main = "Diagrama de barras de Estado_Civil")
pie(table(variable_cualit),col = c("blue","green","orange"),
main = "Diagrama circular Estado_Civil")