Usando la función set.seed(20_ _) y colocando sus dos últimos números de cédula en los espacios con guiones al piso, realice las siguientes actividades:
set.seed(2000)
muestra = rnorm(n=120, mean=5, sd=0.85) %>% round(2)
muestra
## [1] 4.27 4.70 5.76 6.48 5.78 4.00 3.35 6.78 5.19 6.00 6.61 5.71 6.15 4.84 5.16
## [16] 5.92 4.01 5.16 4.01 4.82 5.39 3.50 5.38 5.62 5.32 4.95 3.75 3.55 5.03 5.99
## [31] 4.11 4.51 4.31 4.13 4.15 4.66 5.59 5.46 4.91 4.66 5.00 3.97 5.38 5.26 6.32
## [46] 5.73 5.81 4.55 5.53 5.47 5.67 4.56 4.00 4.22 3.74 5.77 5.85 5.26 4.44 5.80
## [61] 5.85 4.90 4.76 5.13 3.97 5.29 5.77 5.43 3.29 5.02 4.92 4.44 3.63 4.52 4.56
## [76] 5.58 4.48 5.23 5.61 5.69 4.62 4.66 4.76 5.31 5.62 5.05 6.48 4.89 4.53 5.69
## [91] 4.90 5.78 6.59 4.43 5.38 5.25 5.70 2.94 3.98 4.71 6.04 5.49 4.68 4.88 5.32
## [106] 6.39 5.06 6.12 5.51 3.12 4.35 4.87 6.16 5.07 5.28 4.72 6.64 6.54 5.72 4.17
muestra2 = rbinom(n=120, size = 20, prob = 0.8)
muestra2
## [1] 15 17 16 14 18 15 15 16 17 17 19 15 18 18 19 17 15 19 17 15 14 15 15 18 16
## [26] 15 18 16 17 15 16 18 14 17 12 13 17 17 17 17 17 16 13 17 16 13 12 13 16 17
## [51] 16 16 17 15 15 17 15 17 17 16 15 16 13 15 19 16 19 17 15 14 18 17 15 14 17
## [76] 16 16 15 17 14 17 17 18 18 17 13 18 17 15 16 14 17 17 14 19 16 16 16 16 19
## [101] 16 20 14 17 17 18 13 14 19 17 17 13 19 18 15 17 18 15 13 18
muestra3 = rpois(n=120, lambda = 10.5)
muestra3
## [1] 14 13 14 16 6 8 9 12 10 12 9 8 6 11 11 10 14 11 9 5 5 18 16 6 14
## [26] 10 15 10 8 9 12 9 10 14 11 16 16 12 13 11 12 10 13 11 13 9 15 9 18 8
## [51] 8 12 5 9 7 6 14 14 10 17 10 12 16 12 6 16 10 8 10 6 10 13 12 10 6
## [76] 18 16 10 8 11 10 10 14 10 13 10 13 13 12 12 15 17 11 9 14 12 7 12 11 8
## [101] 11 2 13 11 11 8 11 13 9 14 8 6 5 10 12 4 13 10 11 9
muestra4 = sample.int(n=300,120,replace = TRUE)
muestra4
## [1] 104 103 95 4 298 225 278 169 297 116 196 269 108 91 72 55 122 130
## [19] 217 112 45 46 79 125 241 188 56 288 166 105 83 191 72 141 33 40
## [37] 156 77 284 40 68 116 258 222 38 203 281 47 228 244 16 168 119 182
## [55] 26 169 139 129 68 178 8 205 64 251 95 12 210 139 295 150 160 181
## [73] 257 266 139 113 52 244 195 82 80 59 176 130 137 241 118 192 120 190
## [91] 84 155 167 185 278 217 72 32 5 41 228 28 151 187 206 62 220 41
## [109] 167 58 127 107 267 164 287 235 221 204 4 106
muestra5 = rbernoulli(n=120,p=0.75)
muestra5.1= c()
contador = 0
(for(i in muestra5){
contador=contador + 1
if (i==TRUE){
muestra5.1[contador] ="Presente"
} else if (i==FALSE){
muestra5.1[contador]="Ausente"
}
})
## NULL
muestra5.1
## [1] "Presente" "Ausente" "Presente" "Presente" "Presente" "Presente"
## [7] "Presente" "Presente" "Presente" "Presente" "Presente" "Presente"
## [13] "Presente" "Ausente" "Presente" "Presente" "Presente" "Presente"
## [19] "Presente" "Presente" "Presente" "Ausente" "Presente" "Presente"
## [25] "Presente" "Presente" "Presente" "Presente" "Presente" "Ausente"
## [31] "Presente" "Presente" "Ausente" "Presente" "Ausente" "Presente"
## [37] "Presente" "Presente" "Ausente" "Ausente" "Presente" "Ausente"
## [43] "Presente" "Presente" "Ausente" "Ausente" "Presente" "Presente"
## [49] "Presente" "Presente" "Presente" "Presente" "Presente" "Ausente"
## [55] "Presente" "Presente" "Ausente" "Presente" "Presente" "Presente"
## [61] "Presente" "Ausente" "Presente" "Presente" "Presente" "Presente"
## [67] "Presente" "Presente" "Presente" "Ausente" "Presente" "Ausente"
## [73] "Presente" "Presente" "Ausente" "Ausente" "Ausente" "Ausente"
## [79] "Presente" "Ausente" "Ausente" "Ausente" "Ausente" "Presente"
## [85] "Ausente" "Ausente" "Presente" "Presente" "Presente" "Ausente"
## [91] "Ausente" "Presente" "Ausente" "Presente" "Presente" "Presente"
## [97] "Presente" "Presente" "Presente" "Presente" "Presente" "Presente"
## [103] "Presente" "Ausente" "Ausente" "Presente" "Presente" "Presente"
## [109] "Presente" "Presente" "Presente" "Presente" "Presente" "Ausente"
## [115] "Ausente" "Ausente" "Ausente" "Presente" "Presente" "Presente"
niveles = gl(n=3,k=40,length = 3*40, labels = c("S","PA", "MA"))
niveles
## [1] S S S S S S S S S S S S S S S S S S S S S S S S S
## [26] S S S S S S S S S S S S S S S PA PA PA PA PA PA PA PA PA PA
## [51] PA PA PA PA PA PA PA PA PA PA PA PA PA PA PA PA PA PA PA PA PA PA PA PA PA
## [76] PA PA PA PA PA MA MA MA MA MA MA MA MA MA MA MA MA MA MA MA MA MA MA MA MA
## [101] MA MA MA MA MA MA MA MA MA MA MA MA MA MA MA MA MA MA MA MA
## Levels: S PA MA
niveles2 = runif(120,min = 0,max = 1.2)
niveles2.1 = if_else(niveles2 < 0.5,"FO", "FI")
niveles2.1
## [1] "FI" "FI" "FO" "FO" "FO" "FI" "FI" "FI" "FO" "FI" "FO" "FO" "FO" "FO" "FI"
## [16] "FO" "FI" "FO" "FO" "FI" "FO" "FI" "FO" "FI" "FI" "FI" "FI" "FI" "FI" "FO"
## [31] "FI" "FO" "FI" "FI" "FO" "FI" "FI" "FI" "FI" "FI" "FI" "FO" "FI" "FO" "FO"
## [46] "FI" "FO" "FI" "FI" "FI" "FI" "FO" "FI" "FI" "FI" "FI" "FO" "FO" "FI" "FI"
## [61] "FO" "FO" "FO" "FI" "FO" "FI" "FO" "FO" "FO" "FI" "FO" "FO" "FO" "FO" "FI"
## [76] "FO" "FI" "FI" "FI" "FI" "FI" "FI" "FO" "FO" "FO" "FO" "FI" "FO" "FI" "FO"
## [91] "FI" "FI" "FI" "FO" "FO" "FI" "FO" "FI" "FI" "FO" "FO" "FI" "FO" "FO" "FI"
## [106] "FI" "FI" "FO" "FO" "FI" "FI" "FO" "FI" "FO" "FO" "FI" "FI" "FO" "FI" "FO"
Con los datos generados en la actividad 1 desarrolle la siguiente actividad:
df2= data.frame(muestra, muestra2, muestra3, muestra4, muestra5.1,niveles,niveles2.1 )
df= df2 %>% rename(Biomasa=muestra, Flores.r=muestra2, Flores.d=muestra3, Hojas.d=muestra4, Plaga=muestra5.1, Estatus=niveles, Fertilizacion=niveles2.1)
head(df)
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion
## 1 4.27 15 14 104 Presente S FI
## 2 4.70 17 13 103 Ausente S FI
## 3 5.76 16 14 95 Presente S FO
## 4 6.48 14 16 4 Presente S FO
## 5 5.78 18 6 298 Presente S FO
## 6 4.00 15 8 225 Presente S FI
df%>%dim()
## [1] 120 7
df%>%str()
## 'data.frame': 120 obs. of 7 variables:
## $ Biomasa : num 4.27 4.7 5.76 6.48 5.78 4 3.35 6.78 5.19 6 ...
## $ Flores.r : int 15 17 16 14 18 15 15 16 17 17 ...
## $ Flores.d : int 14 13 14 16 6 8 9 12 10 12 ...
## $ Hojas.d : int 104 103 95 4 298 225 278 169 297 116 ...
## $ Plaga : chr "Presente" "Ausente" "Presente" "Presente" ...
## $ Estatus : Factor w/ 3 levels "S","PA","MA": 1 1 1 1 1 1 1 1 1 1 ...
## $ Fertilizacion: chr "FI" "FI" "FO" "FO" ...
df%>%class()
## [1] "data.frame"
df%>%names()
## [1] "Biomasa" "Flores.r" "Flores.d" "Hojas.d"
## [5] "Plaga" "Estatus" "Fertilizacion"
df%>%is.na()%>%sum()
## [1] 0
df75=df%>%sample_n((120*75/100),replace = TRUE)
df75[15,1]=NA
df75[30,3]=NA
df75
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion
## 1 5.13 15 12 251 Presente PA FI
## 2 4.11 16 12 83 Presente S FI
## 3 3.63 15 12 257 Presente PA FO
## 4 2.94 16 12 32 Presente MA FI
## 5 4.76 18 14 176 Ausente MA FO
## 6 4.89 17 13 192 Presente MA FO
## 7 5.16 19 11 130 Presente S FO
## 8 3.63 15 12 257 Presente PA FO
## 9 5.06 13 11 220 Presente MA FI
## 10 4.89 17 13 192 Presente MA FO
## 11 5.49 20 2 28 Presente MA FI
## 12 4.35 17 8 127 Presente MA FI
## 13 5.13 15 12 251 Presente PA FI
## 14 5.23 15 10 244 Ausente PA FI
## 15 NA 17 11 187 Ausente MA FO
## 16 5.78 17 17 155 Presente MA FI
## 17 4.70 17 13 103 Ausente S FI
## 18 4.87 13 6 107 Presente MA FO
## 19 5.16 19 11 130 Presente S FO
## 20 6.54 15 10 204 Presente MA FO
## 21 5.76 16 14 95 Presente S FO
## 22 5.16 19 11 130 Presente S FO
## 23 4.90 16 12 205 Ausente PA FO
## 24 5.99 15 9 105 Ausente S FO
## 25 5.25 16 12 217 Presente MA FI
## 26 6.48 14 16 4 Presente S FO
## 27 5.85 15 10 8 Presente PA FO
## 28 6.48 14 16 4 Presente S FO
## 29 5.61 17 8 195 Presente PA FI
## 30 6.54 15 NA 204 Presente MA FO
## 31 5.38 13 13 258 Presente PA FI
## 32 5.26 17 14 129 Presente PA FO
## 33 3.75 18 15 56 Presente S FI
## 34 6.59 17 11 167 Ausente MA FI
## 35 5.38 15 16 79 Presente S FO
## 36 4.89 17 13 192 Presente MA FO
## 37 3.74 15 7 26 Presente PA FI
## 38 4.13 17 14 141 Presente S FI
## 39 4.66 17 11 40 Ausente S FI
## 40 4.00 17 5 119 Presente PA FI
## 41 4.55 13 9 47 Presente PA FI
## 42 5.72 13 11 4 Presente MA FI
## 43 6.12 14 13 41 Presente MA FO
## 44 4.66 13 16 40 Presente S FI
## 45 5.99 15 9 105 Ausente S FO
## 46 4.82 15 5 112 Presente S FI
## 47 4.51 18 9 191 Presente S FO
## 48 5.69 14 11 82 Ausente PA FI
## 49 5.32 16 14 241 Presente S FI
## 50 4.44 17 13 181 Ausente PA FO
## 51 4.62 17 10 80 Ausente MA FI
## 52 4.91 17 13 284 Ausente S FI
## 53 3.12 17 14 58 Presente MA FI
## 54 5.31 18 10 130 Presente MA FO
## 55 5.76 16 14 95 Presente S FO
## 56 5.49 20 2 28 Presente MA FI
## 57 4.84 18 11 91 Ausente S FO
## 58 5.81 12 15 281 Presente PA FO
## 59 5.23 15 10 244 Ausente PA FI
## 60 3.63 15 12 257 Presente PA FO
## 61 4.66 17 11 40 Ausente S FI
## 62 4.43 14 9 185 Presente MA FO
## 63 5.80 16 17 178 Presente PA FI
## 64 4.84 18 11 91 Ausente S FO
## 65 3.97 19 6 95 Presente PA FO
## 66 3.55 16 10 288 Presente S FI
## 67 5.28 15 12 287 Ausente MA FO
## 68 5.29 16 16 12 Presente PA FI
## 69 5.69 14 11 82 Ausente PA FI
## 70 5.03 17 8 166 Presente S FI
## 71 3.97 16 10 116 Ausente PA FO
## 72 5.28 15 12 287 Ausente MA FO
## 73 5.81 12 15 281 Presente PA FO
## 74 6.48 18 13 118 Presente MA FI
## 75 4.43 14 9 185 Presente MA FO
## 76 3.97 19 6 95 Presente PA FO
## 77 5.77 19 10 210 Presente PA FO
## 78 5.28 15 12 287 Ausente MA FO
## 79 5.07 18 10 164 Ausente MA FO
## 80 2.94 16 12 32 Presente MA FI
## 81 5.80 16 17 178 Presente PA FI
## 82 4.82 15 5 112 Presente S FI
## 83 4.48 16 16 52 Ausente PA FI
## 84 5.47 17 8 244 Presente PA FI
## 85 4.72 17 4 235 Ausente MA FI
## 86 4.92 18 10 160 Presente PA FO
## 87 4.68 14 13 151 Presente MA FO
## 88 3.55 16 10 288 Presente S FI
## 89 4.66 17 11 40 Ausente S FI
## 90 4.53 15 12 120 Presente MA FI
Ya tenemos dos conjuntos de datos, los que podemos guardar como tib.c al completo y tib.i al incompleto. Ahora si podemos usar algunas de las funciones de dplyr() consideradas en clase.
tib.c=df
tib.i=df75
tib.c%>%
select(Biomasa) %>%
head
## Biomasa
## 1 4.27
## 2 4.70
## 3 5.76
## 4 6.48
## 5 5.78
## 6 4.00
tib.c%>%
select(3:6) %>%
head
## Flores.d Hojas.d Plaga Estatus
## 1 14 104 Presente S
## 2 13 103 Ausente S
## 3 14 95 Presente S
## 4 16 4 Presente S
## 5 6 298 Presente S
## 6 8 225 Presente S
tib.c%>%
select(!(3:6)) %>%
head
## Biomasa Flores.r Fertilizacion
## 1 4.27 15 FI
## 2 4.70 17 FI
## 3 5.76 16 FO
## 4 6.48 14 FO
## 5 5.78 18 FO
## 6 4.00 15 FI
tib.c%>%
select(!ends_with(".d")) %>%
head
## Biomasa Flores.r Plaga Estatus Fertilizacion
## 1 4.27 15 Presente S FI
## 2 4.70 17 Ausente S FI
## 3 5.76 16 Presente S FO
## 4 6.48 14 Presente S FO
## 5 5.78 18 Presente S FO
## 6 4.00 15 Presente S FI
tib.c%>%
select(starts_with("Fl")) %>%
head
## Flores.r Flores.d
## 1 15 14
## 2 17 13
## 3 16 14
## 4 14 16
## 5 18 6
## 6 15 8
tib.c%>%
select(starts_with("F")&ends_with(".d")) %>%
head
## Flores.d
## 1 14
## 2 13
## 3 14
## 4 16
## 5 6
## 6 8
tib.c%>%
select(Flores.r,Estatus)%>%
group_by(Estatus)
## # A tibble: 120 x 2
## # Groups: Estatus [3]
## Flores.r Estatus
## <int> <fct>
## 1 15 S
## 2 17 S
## 3 16 S
## 4 14 S
## 5 18 S
## 6 15 S
## 7 15 S
## 8 16 S
## 9 17 S
## 10 17 S
## # ... with 110 more rows
var_estatus=tib.c%>%select(Flores.r,Estatus)%>%group_by(Estatus)
tib.c%>%arrange(desc(var_estatus),.by_group=TRUE)
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion
## 1 5.49 20 2 28 Presente MA FI
## 2 5.38 19 14 278 Presente MA FO
## 3 4.71 19 8 41 Presente MA FO
## 4 5.51 19 9 167 Presente MA FO
## 5 6.16 19 5 267 Presente MA FI
## 6 3.97 19 6 95 Presente PA FO
## 7 5.77 19 10 210 Presente PA FO
## 8 6.61 19 9 196 Presente S FO
## 9 5.16 19 11 72 Presente S FI
## 10 5.16 19 11 130 Presente S FO
## 11 4.76 18 14 176 Ausente MA FO
## 12 5.31 18 10 130 Presente MA FO
## 13 6.48 18 13 118 Presente MA FI
## 14 6.39 18 8 62 Presente MA FI
## 15 5.07 18 10 164 Ausente MA FO
## 16 6.64 18 13 221 Ausente MA FI
## 17 4.17 18 9 106 Presente MA FO
## 18 4.92 18 10 160 Presente PA FO
## 19 5.78 18 6 298 Presente S FO
## 20 6.15 18 6 108 Presente S FO
## 21 4.84 18 11 91 Ausente S FO
## 22 5.62 18 6 125 Presente S FI
## 23 3.75 18 15 56 Presente S FI
## 24 4.51 18 9 191 Presente S FO
## 25 4.62 17 10 80 Ausente MA FI
## 26 4.66 17 10 59 Ausente MA FI
## 27 5.62 17 13 137 Ausente MA FO
## 28 4.89 17 13 192 Presente MA FO
## 29 5.78 17 17 155 Presente MA FI
## 30 6.59 17 11 167 Ausente MA FI
## 31 4.88 17 11 187 Ausente MA FO
## 32 5.32 17 11 206 Ausente MA FI
## 33 3.12 17 14 58 Presente MA FI
## 34 4.35 17 8 127 Presente MA FI
## 35 4.72 17 4 235 Ausente MA FI
## 36 5.00 17 12 68 Presente PA FI
## 37 5.26 17 11 222 Presente PA FO
## 38 5.47 17 8 244 Presente PA FI
## 39 4.00 17 5 119 Presente PA FI
## 40 5.77 17 6 169 Presente PA FI
## 41 5.26 17 14 129 Presente PA FO
## 42 4.44 17 10 68 Presente PA FI
## 43 5.43 17 8 139 Presente PA FO
## 44 4.44 17 13 181 Ausente PA FO
## 45 4.56 17 6 139 Ausente PA FI
## 46 5.61 17 8 195 Presente PA FI
## 47 4.70 17 13 103 Ausente S FI
## 48 5.19 17 10 297 Presente S FO
## 49 6.00 17 12 116 Presente S FI
## 50 5.92 17 10 55 Presente S FO
## 51 4.01 17 9 217 Presente S FO
## 52 5.03 17 8 166 Presente S FI
## 53 4.13 17 14 141 Presente S FI
## 54 5.59 17 16 156 Presente S FI
## 55 5.46 17 12 77 Presente S FI
## 56 4.91 17 13 284 Ausente S FI
## 57 4.66 17 11 40 Ausente S FI
## 58 5.69 16 12 190 Ausente MA FO
## 59 5.25 16 12 217 Presente MA FI
## 60 5.70 16 7 72 Presente MA FO
## 61 2.94 16 12 32 Presente MA FI
## 62 3.98 16 11 5 Presente MA FI
## 63 6.04 16 11 228 Presente MA FO
## 64 3.97 16 10 116 Ausente PA FO
## 65 6.32 16 13 38 Ausente PA FO
## 66 5.53 16 18 228 Presente PA FI
## 67 5.67 16 8 16 Presente PA FI
## 68 4.56 16 12 168 Presente PA FO
## 69 5.80 16 17 178 Presente PA FI
## 70 4.90 16 12 205 Ausente PA FO
## 71 5.29 16 16 12 Presente PA FI
## 72 5.58 16 18 113 Ausente PA FO
## 73 4.48 16 16 52 Ausente PA FI
## 74 5.76 16 14 95 Presente S FO
## 75 6.78 16 12 169 Presente S FI
## 76 5.32 16 14 241 Presente S FI
## 77 3.55 16 10 288 Presente S FI
## 78 4.11 16 12 83 Presente S FI
## 79 4.53 15 12 120 Presente MA FI
## 80 5.28 15 12 287 Ausente MA FO
## 81 6.54 15 10 204 Presente MA FO
## 82 4.22 15 9 182 Ausente PA FI
## 83 3.74 15 7 26 Presente PA FI
## 84 5.85 15 14 139 Ausente PA FO
## 85 5.85 15 10 8 Presente PA FO
## 86 5.13 15 12 251 Presente PA FI
## 87 3.29 15 10 295 Presente PA FO
## 88 3.63 15 12 257 Presente PA FO
## 89 5.23 15 10 244 Ausente PA FI
## 90 4.27 15 14 104 Presente S FI
## 91 4.00 15 8 225 Presente S FI
## 92 3.35 15 9 278 Presente S FI
## 93 5.71 15 8 269 Presente S FO
## 94 4.01 15 14 122 Presente S FI
## 95 4.82 15 5 112 Presente S FI
## 96 3.50 15 18 46 Ausente S FI
## 97 5.38 15 16 79 Presente S FO
## 98 4.95 15 10 188 Presente S FI
## 99 5.99 15 9 105 Ausente S FO
## 100 4.90 14 15 84 Ausente MA FI
## 101 4.43 14 9 185 Presente MA FO
## 102 4.68 14 13 151 Presente MA FO
## 103 6.12 14 13 41 Presente MA FO
## 104 5.02 14 6 150 Ausente PA FI
## 105 4.52 14 10 266 Presente PA FO
## 106 5.69 14 11 82 Ausente PA FI
## 107 6.48 14 16 4 Presente S FO
## 108 5.39 14 5 45 Presente S FO
## 109 4.31 14 10 72 Ausente S FI
## 110 5.05 13 10 241 Ausente MA FO
## 111 5.06 13 11 220 Presente MA FI
## 112 4.87 13 6 107 Presente MA FO
## 113 5.72 13 11 4 Presente MA FI
## 114 5.38 13 13 258 Presente PA FI
## 115 5.73 13 9 203 Ausente PA FI
## 116 4.55 13 9 47 Presente PA FI
## 117 4.76 13 16 64 Presente PA FO
## 118 4.66 13 16 40 Presente S FI
## 119 5.81 12 15 281 Presente PA FO
## 120 4.15 12 11 33 Ausente S FO
tib.c
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion
## 1 4.27 15 14 104 Presente S FI
## 2 4.70 17 13 103 Ausente S FI
## 3 5.76 16 14 95 Presente S FO
## 4 6.48 14 16 4 Presente S FO
## 5 5.78 18 6 298 Presente S FO
## 6 4.00 15 8 225 Presente S FI
## 7 3.35 15 9 278 Presente S FI
## 8 6.78 16 12 169 Presente S FI
## 9 5.19 17 10 297 Presente S FO
## 10 6.00 17 12 116 Presente S FI
## 11 6.61 19 9 196 Presente S FO
## 12 5.71 15 8 269 Presente S FO
## 13 6.15 18 6 108 Presente S FO
## 14 4.84 18 11 91 Ausente S FO
## 15 5.16 19 11 72 Presente S FI
## 16 5.92 17 10 55 Presente S FO
## 17 4.01 15 14 122 Presente S FI
## 18 5.16 19 11 130 Presente S FO
## 19 4.01 17 9 217 Presente S FO
## 20 4.82 15 5 112 Presente S FI
## 21 5.39 14 5 45 Presente S FO
## 22 3.50 15 18 46 Ausente S FI
## 23 5.38 15 16 79 Presente S FO
## 24 5.62 18 6 125 Presente S FI
## 25 5.32 16 14 241 Presente S FI
## 26 4.95 15 10 188 Presente S FI
## 27 3.75 18 15 56 Presente S FI
## 28 3.55 16 10 288 Presente S FI
## 29 5.03 17 8 166 Presente S FI
## 30 5.99 15 9 105 Ausente S FO
## 31 4.11 16 12 83 Presente S FI
## 32 4.51 18 9 191 Presente S FO
## 33 4.31 14 10 72 Ausente S FI
## 34 4.13 17 14 141 Presente S FI
## 35 4.15 12 11 33 Ausente S FO
## 36 4.66 13 16 40 Presente S FI
## 37 5.59 17 16 156 Presente S FI
## 38 5.46 17 12 77 Presente S FI
## 39 4.91 17 13 284 Ausente S FI
## 40 4.66 17 11 40 Ausente S FI
## 41 5.00 17 12 68 Presente PA FI
## 42 3.97 16 10 116 Ausente PA FO
## 43 5.38 13 13 258 Presente PA FI
## 44 5.26 17 11 222 Presente PA FO
## 45 6.32 16 13 38 Ausente PA FO
## 46 5.73 13 9 203 Ausente PA FI
## 47 5.81 12 15 281 Presente PA FO
## 48 4.55 13 9 47 Presente PA FI
## 49 5.53 16 18 228 Presente PA FI
## 50 5.47 17 8 244 Presente PA FI
## 51 5.67 16 8 16 Presente PA FI
## 52 4.56 16 12 168 Presente PA FO
## 53 4.00 17 5 119 Presente PA FI
## 54 4.22 15 9 182 Ausente PA FI
## 55 3.74 15 7 26 Presente PA FI
## 56 5.77 17 6 169 Presente PA FI
## 57 5.85 15 14 139 Ausente PA FO
## 58 5.26 17 14 129 Presente PA FO
## 59 4.44 17 10 68 Presente PA FI
## 60 5.80 16 17 178 Presente PA FI
## 61 5.85 15 10 8 Presente PA FO
## 62 4.90 16 12 205 Ausente PA FO
## 63 4.76 13 16 64 Presente PA FO
## 64 5.13 15 12 251 Presente PA FI
## 65 3.97 19 6 95 Presente PA FO
## 66 5.29 16 16 12 Presente PA FI
## 67 5.77 19 10 210 Presente PA FO
## 68 5.43 17 8 139 Presente PA FO
## 69 3.29 15 10 295 Presente PA FO
## 70 5.02 14 6 150 Ausente PA FI
## 71 4.92 18 10 160 Presente PA FO
## 72 4.44 17 13 181 Ausente PA FO
## 73 3.63 15 12 257 Presente PA FO
## 74 4.52 14 10 266 Presente PA FO
## 75 4.56 17 6 139 Ausente PA FI
## 76 5.58 16 18 113 Ausente PA FO
## 77 4.48 16 16 52 Ausente PA FI
## 78 5.23 15 10 244 Ausente PA FI
## 79 5.61 17 8 195 Presente PA FI
## 80 5.69 14 11 82 Ausente PA FI
## 81 4.62 17 10 80 Ausente MA FI
## 82 4.66 17 10 59 Ausente MA FI
## 83 4.76 18 14 176 Ausente MA FO
## 84 5.31 18 10 130 Presente MA FO
## 85 5.62 17 13 137 Ausente MA FO
## 86 5.05 13 10 241 Ausente MA FO
## 87 6.48 18 13 118 Presente MA FI
## 88 4.89 17 13 192 Presente MA FO
## 89 4.53 15 12 120 Presente MA FI
## 90 5.69 16 12 190 Ausente MA FO
## 91 4.90 14 15 84 Ausente MA FI
## 92 5.78 17 17 155 Presente MA FI
## 93 6.59 17 11 167 Ausente MA FI
## 94 4.43 14 9 185 Presente MA FO
## 95 5.38 19 14 278 Presente MA FO
## 96 5.25 16 12 217 Presente MA FI
## 97 5.70 16 7 72 Presente MA FO
## 98 2.94 16 12 32 Presente MA FI
## 99 3.98 16 11 5 Presente MA FI
## 100 4.71 19 8 41 Presente MA FO
## 101 6.04 16 11 228 Presente MA FO
## 102 5.49 20 2 28 Presente MA FI
## 103 4.68 14 13 151 Presente MA FO
## 104 4.88 17 11 187 Ausente MA FO
## 105 5.32 17 11 206 Ausente MA FI
## 106 6.39 18 8 62 Presente MA FI
## 107 5.06 13 11 220 Presente MA FI
## 108 6.12 14 13 41 Presente MA FO
## 109 5.51 19 9 167 Presente MA FO
## 110 3.12 17 14 58 Presente MA FI
## 111 4.35 17 8 127 Presente MA FI
## 112 4.87 13 6 107 Presente MA FO
## 113 6.16 19 5 267 Presente MA FI
## 114 5.07 18 10 164 Ausente MA FO
## 115 5.28 15 12 287 Ausente MA FO
## 116 4.72 17 4 235 Ausente MA FI
## 117 6.64 18 13 221 Ausente MA FI
## 118 6.54 15 10 204 Presente MA FO
## 119 5.72 13 11 4 Presente MA FI
## 120 4.17 18 9 106 Presente MA FO
tib.c %>%
select(starts_with("Flores"),Estatus) %>%
filter(Estatus == "MA")
## Flores.r Flores.d Estatus
## 1 17 10 MA
## 2 17 10 MA
## 3 18 14 MA
## 4 18 10 MA
## 5 17 13 MA
## 6 13 10 MA
## 7 18 13 MA
## 8 17 13 MA
## 9 15 12 MA
## 10 16 12 MA
## 11 14 15 MA
## 12 17 17 MA
## 13 17 11 MA
## 14 14 9 MA
## 15 19 14 MA
## 16 16 12 MA
## 17 16 7 MA
## 18 16 12 MA
## 19 16 11 MA
## 20 19 8 MA
## 21 16 11 MA
## 22 20 2 MA
## 23 14 13 MA
## 24 17 11 MA
## 25 17 11 MA
## 26 18 8 MA
## 27 13 11 MA
## 28 14 13 MA
## 29 19 9 MA
## 30 17 14 MA
## 31 17 8 MA
## 32 13 6 MA
## 33 19 5 MA
## 34 18 10 MA
## 35 15 12 MA
## 36 17 4 MA
## 37 18 13 MA
## 38 15 10 MA
## 39 13 11 MA
## 40 18 9 MA
tib.c%>%filter(Biomasa >5)
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion
## 1 5.76 16 14 95 Presente S FO
## 2 6.48 14 16 4 Presente S FO
## 3 5.78 18 6 298 Presente S FO
## 4 6.78 16 12 169 Presente S FI
## 5 5.19 17 10 297 Presente S FO
## 6 6.00 17 12 116 Presente S FI
## 7 6.61 19 9 196 Presente S FO
## 8 5.71 15 8 269 Presente S FO
## 9 6.15 18 6 108 Presente S FO
## 10 5.16 19 11 72 Presente S FI
## 11 5.92 17 10 55 Presente S FO
## 12 5.16 19 11 130 Presente S FO
## 13 5.39 14 5 45 Presente S FO
## 14 5.38 15 16 79 Presente S FO
## 15 5.62 18 6 125 Presente S FI
## 16 5.32 16 14 241 Presente S FI
## 17 5.03 17 8 166 Presente S FI
## 18 5.99 15 9 105 Ausente S FO
## 19 5.59 17 16 156 Presente S FI
## 20 5.46 17 12 77 Presente S FI
## 21 5.38 13 13 258 Presente PA FI
## 22 5.26 17 11 222 Presente PA FO
## 23 6.32 16 13 38 Ausente PA FO
## 24 5.73 13 9 203 Ausente PA FI
## 25 5.81 12 15 281 Presente PA FO
## 26 5.53 16 18 228 Presente PA FI
## 27 5.47 17 8 244 Presente PA FI
## 28 5.67 16 8 16 Presente PA FI
## 29 5.77 17 6 169 Presente PA FI
## 30 5.85 15 14 139 Ausente PA FO
## 31 5.26 17 14 129 Presente PA FO
## 32 5.80 16 17 178 Presente PA FI
## 33 5.85 15 10 8 Presente PA FO
## 34 5.13 15 12 251 Presente PA FI
## 35 5.29 16 16 12 Presente PA FI
## 36 5.77 19 10 210 Presente PA FO
## 37 5.43 17 8 139 Presente PA FO
## 38 5.02 14 6 150 Ausente PA FI
## 39 5.58 16 18 113 Ausente PA FO
## 40 5.23 15 10 244 Ausente PA FI
## 41 5.61 17 8 195 Presente PA FI
## 42 5.69 14 11 82 Ausente PA FI
## 43 5.31 18 10 130 Presente MA FO
## 44 5.62 17 13 137 Ausente MA FO
## 45 5.05 13 10 241 Ausente MA FO
## 46 6.48 18 13 118 Presente MA FI
## 47 5.69 16 12 190 Ausente MA FO
## 48 5.78 17 17 155 Presente MA FI
## 49 6.59 17 11 167 Ausente MA FI
## 50 5.38 19 14 278 Presente MA FO
## 51 5.25 16 12 217 Presente MA FI
## 52 5.70 16 7 72 Presente MA FO
## 53 6.04 16 11 228 Presente MA FO
## 54 5.49 20 2 28 Presente MA FI
## 55 5.32 17 11 206 Ausente MA FI
## 56 6.39 18 8 62 Presente MA FI
## 57 5.06 13 11 220 Presente MA FI
## 58 6.12 14 13 41 Presente MA FO
## 59 5.51 19 9 167 Presente MA FO
## 60 6.16 19 5 267 Presente MA FI
## 61 5.07 18 10 164 Ausente MA FO
## 62 5.28 15 12 287 Ausente MA FO
## 63 6.64 18 13 221 Ausente MA FI
## 64 6.54 15 10 204 Presente MA FO
## 65 5.72 13 11 4 Presente MA FI
tib.c%>%filter(Estatus=="PA" & Fertilizacion=="FO")
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion
## 1 3.97 16 10 116 Ausente PA FO
## 2 5.26 17 11 222 Presente PA FO
## 3 6.32 16 13 38 Ausente PA FO
## 4 5.81 12 15 281 Presente PA FO
## 5 4.56 16 12 168 Presente PA FO
## 6 5.85 15 14 139 Ausente PA FO
## 7 5.26 17 14 129 Presente PA FO
## 8 5.85 15 10 8 Presente PA FO
## 9 4.90 16 12 205 Ausente PA FO
## 10 4.76 13 16 64 Presente PA FO
## 11 3.97 19 6 95 Presente PA FO
## 12 5.77 19 10 210 Presente PA FO
## 13 5.43 17 8 139 Presente PA FO
## 14 3.29 15 10 295 Presente PA FO
## 15 4.92 18 10 160 Presente PA FO
## 16 4.44 17 13 181 Ausente PA FO
## 17 3.63 15 12 257 Presente PA FO
## 18 4.52 14 10 266 Presente PA FO
## 19 5.58 16 18 113 Ausente PA FO
tib.c%>%filter(Estatus=="PA" | Fertilizacion=="FI")
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion
## 1 4.27 15 14 104 Presente S FI
## 2 4.70 17 13 103 Ausente S FI
## 3 4.00 15 8 225 Presente S FI
## 4 3.35 15 9 278 Presente S FI
## 5 6.78 16 12 169 Presente S FI
## 6 6.00 17 12 116 Presente S FI
## 7 5.16 19 11 72 Presente S FI
## 8 4.01 15 14 122 Presente S FI
## 9 4.82 15 5 112 Presente S FI
## 10 3.50 15 18 46 Ausente S FI
## 11 5.62 18 6 125 Presente S FI
## 12 5.32 16 14 241 Presente S FI
## 13 4.95 15 10 188 Presente S FI
## 14 3.75 18 15 56 Presente S FI
## 15 3.55 16 10 288 Presente S FI
## 16 5.03 17 8 166 Presente S FI
## 17 4.11 16 12 83 Presente S FI
## 18 4.31 14 10 72 Ausente S FI
## 19 4.13 17 14 141 Presente S FI
## 20 4.66 13 16 40 Presente S FI
## 21 5.59 17 16 156 Presente S FI
## 22 5.46 17 12 77 Presente S FI
## 23 4.91 17 13 284 Ausente S FI
## 24 4.66 17 11 40 Ausente S FI
## 25 5.00 17 12 68 Presente PA FI
## 26 3.97 16 10 116 Ausente PA FO
## 27 5.38 13 13 258 Presente PA FI
## 28 5.26 17 11 222 Presente PA FO
## 29 6.32 16 13 38 Ausente PA FO
## 30 5.73 13 9 203 Ausente PA FI
## 31 5.81 12 15 281 Presente PA FO
## 32 4.55 13 9 47 Presente PA FI
## 33 5.53 16 18 228 Presente PA FI
## 34 5.47 17 8 244 Presente PA FI
## 35 5.67 16 8 16 Presente PA FI
## 36 4.56 16 12 168 Presente PA FO
## 37 4.00 17 5 119 Presente PA FI
## 38 4.22 15 9 182 Ausente PA FI
## 39 3.74 15 7 26 Presente PA FI
## 40 5.77 17 6 169 Presente PA FI
## 41 5.85 15 14 139 Ausente PA FO
## 42 5.26 17 14 129 Presente PA FO
## 43 4.44 17 10 68 Presente PA FI
## 44 5.80 16 17 178 Presente PA FI
## 45 5.85 15 10 8 Presente PA FO
## 46 4.90 16 12 205 Ausente PA FO
## 47 4.76 13 16 64 Presente PA FO
## 48 5.13 15 12 251 Presente PA FI
## 49 3.97 19 6 95 Presente PA FO
## 50 5.29 16 16 12 Presente PA FI
## 51 5.77 19 10 210 Presente PA FO
## 52 5.43 17 8 139 Presente PA FO
## 53 3.29 15 10 295 Presente PA FO
## 54 5.02 14 6 150 Ausente PA FI
## 55 4.92 18 10 160 Presente PA FO
## 56 4.44 17 13 181 Ausente PA FO
## 57 3.63 15 12 257 Presente PA FO
## 58 4.52 14 10 266 Presente PA FO
## 59 4.56 17 6 139 Ausente PA FI
## 60 5.58 16 18 113 Ausente PA FO
## 61 4.48 16 16 52 Ausente PA FI
## 62 5.23 15 10 244 Ausente PA FI
## 63 5.61 17 8 195 Presente PA FI
## 64 5.69 14 11 82 Ausente PA FI
## 65 4.62 17 10 80 Ausente MA FI
## 66 4.66 17 10 59 Ausente MA FI
## 67 6.48 18 13 118 Presente MA FI
## 68 4.53 15 12 120 Presente MA FI
## 69 4.90 14 15 84 Ausente MA FI
## 70 5.78 17 17 155 Presente MA FI
## 71 6.59 17 11 167 Ausente MA FI
## 72 5.25 16 12 217 Presente MA FI
## 73 2.94 16 12 32 Presente MA FI
## 74 3.98 16 11 5 Presente MA FI
## 75 5.49 20 2 28 Presente MA FI
## 76 5.32 17 11 206 Ausente MA FI
## 77 6.39 18 8 62 Presente MA FI
## 78 5.06 13 11 220 Presente MA FI
## 79 3.12 17 14 58 Presente MA FI
## 80 4.35 17 8 127 Presente MA FI
## 81 6.16 19 5 267 Presente MA FI
## 82 4.72 17 4 235 Ausente MA FI
## 83 6.64 18 13 221 Ausente MA FI
## 84 5.72 13 11 4 Presente MA FI
tib.c%>%filter(Flores.d > median(Flores.d))
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion
## 1 4.27 15 14 104 Presente S FI
## 2 4.70 17 13 103 Ausente S FI
## 3 5.76 16 14 95 Presente S FO
## 4 6.48 14 16 4 Presente S FO
## 5 6.78 16 12 169 Presente S FI
## 6 6.00 17 12 116 Presente S FI
## 7 4.01 15 14 122 Presente S FI
## 8 3.50 15 18 46 Ausente S FI
## 9 5.38 15 16 79 Presente S FO
## 10 5.32 16 14 241 Presente S FI
## 11 3.75 18 15 56 Presente S FI
## 12 4.11 16 12 83 Presente S FI
## 13 4.13 17 14 141 Presente S FI
## 14 4.66 13 16 40 Presente S FI
## 15 5.59 17 16 156 Presente S FI
## 16 5.46 17 12 77 Presente S FI
## 17 4.91 17 13 284 Ausente S FI
## 18 5.00 17 12 68 Presente PA FI
## 19 5.38 13 13 258 Presente PA FI
## 20 6.32 16 13 38 Ausente PA FO
## 21 5.81 12 15 281 Presente PA FO
## 22 5.53 16 18 228 Presente PA FI
## 23 4.56 16 12 168 Presente PA FO
## 24 5.85 15 14 139 Ausente PA FO
## 25 5.26 17 14 129 Presente PA FO
## 26 5.80 16 17 178 Presente PA FI
## 27 4.90 16 12 205 Ausente PA FO
## 28 4.76 13 16 64 Presente PA FO
## 29 5.13 15 12 251 Presente PA FI
## 30 5.29 16 16 12 Presente PA FI
## 31 4.44 17 13 181 Ausente PA FO
## 32 3.63 15 12 257 Presente PA FO
## 33 5.58 16 18 113 Ausente PA FO
## 34 4.48 16 16 52 Ausente PA FI
## 35 4.76 18 14 176 Ausente MA FO
## 36 5.62 17 13 137 Ausente MA FO
## 37 6.48 18 13 118 Presente MA FI
## 38 4.89 17 13 192 Presente MA FO
## 39 4.53 15 12 120 Presente MA FI
## 40 5.69 16 12 190 Ausente MA FO
## 41 4.90 14 15 84 Ausente MA FI
## 42 5.78 17 17 155 Presente MA FI
## 43 5.38 19 14 278 Presente MA FO
## 44 5.25 16 12 217 Presente MA FI
## 45 2.94 16 12 32 Presente MA FI
## 46 4.68 14 13 151 Presente MA FO
## 47 6.12 14 13 41 Presente MA FO
## 48 3.12 17 14 58 Presente MA FI
## 49 5.28 15 12 287 Ausente MA FO
## 50 6.64 18 13 221 Ausente MA FI
tib.i%>%filter(Flores.d > median(Flores.d, na.rm=TRUE),Plaga=="Presente")
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion
## 1 5.13 15 12 251 Presente PA FI
## 2 4.11 16 12 83 Presente S FI
## 3 3.63 15 12 257 Presente PA FO
## 4 2.94 16 12 32 Presente MA FI
## 5 4.89 17 13 192 Presente MA FO
## 6 3.63 15 12 257 Presente PA FO
## 7 4.89 17 13 192 Presente MA FO
## 8 5.13 15 12 251 Presente PA FI
## 9 5.78 17 17 155 Presente MA FI
## 10 5.76 16 14 95 Presente S FO
## 11 5.25 16 12 217 Presente MA FI
## 12 6.48 14 16 4 Presente S FO
## 13 6.48 14 16 4 Presente S FO
## 14 5.38 13 13 258 Presente PA FI
## 15 5.26 17 14 129 Presente PA FO
## 16 3.75 18 15 56 Presente S FI
## 17 5.38 15 16 79 Presente S FO
## 18 4.89 17 13 192 Presente MA FO
## 19 4.13 17 14 141 Presente S FI
## 20 6.12 14 13 41 Presente MA FO
## 21 4.66 13 16 40 Presente S FI
## 22 5.32 16 14 241 Presente S FI
## 23 3.12 17 14 58 Presente MA FI
## 24 5.76 16 14 95 Presente S FO
## 25 5.81 12 15 281 Presente PA FO
## 26 3.63 15 12 257 Presente PA FO
## 27 5.80 16 17 178 Presente PA FI
## 28 5.29 16 16 12 Presente PA FI
## 29 5.81 12 15 281 Presente PA FO
## 30 6.48 18 13 118 Presente MA FI
## 31 2.94 16 12 32 Presente MA FI
## 32 5.80 16 17 178 Presente PA FI
## 33 4.68 14 13 151 Presente MA FO
## 34 4.53 15 12 120 Presente MA FI
tib.c%>%filter(Flores.d > median(Flores.d),Plaga=="Presente")
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion
## 1 4.27 15 14 104 Presente S FI
## 2 5.76 16 14 95 Presente S FO
## 3 6.48 14 16 4 Presente S FO
## 4 6.78 16 12 169 Presente S FI
## 5 6.00 17 12 116 Presente S FI
## 6 4.01 15 14 122 Presente S FI
## 7 5.38 15 16 79 Presente S FO
## 8 5.32 16 14 241 Presente S FI
## 9 3.75 18 15 56 Presente S FI
## 10 4.11 16 12 83 Presente S FI
## 11 4.13 17 14 141 Presente S FI
## 12 4.66 13 16 40 Presente S FI
## 13 5.59 17 16 156 Presente S FI
## 14 5.46 17 12 77 Presente S FI
## 15 5.00 17 12 68 Presente PA FI
## 16 5.38 13 13 258 Presente PA FI
## 17 5.81 12 15 281 Presente PA FO
## 18 5.53 16 18 228 Presente PA FI
## 19 4.56 16 12 168 Presente PA FO
## 20 5.26 17 14 129 Presente PA FO
## 21 5.80 16 17 178 Presente PA FI
## 22 4.76 13 16 64 Presente PA FO
## 23 5.13 15 12 251 Presente PA FI
## 24 5.29 16 16 12 Presente PA FI
## 25 3.63 15 12 257 Presente PA FO
## 26 6.48 18 13 118 Presente MA FI
## 27 4.89 17 13 192 Presente MA FO
## 28 4.53 15 12 120 Presente MA FI
## 29 5.78 17 17 155 Presente MA FI
## 30 5.38 19 14 278 Presente MA FO
## 31 5.25 16 12 217 Presente MA FI
## 32 2.94 16 12 32 Presente MA FI
## 33 4.68 14 13 151 Presente MA FO
## 34 6.12 14 13 41 Presente MA FO
## 35 3.12 17 14 58 Presente MA FI
quantile(tib.c$Biomasa,0.25)
## 25%
## 4.5275
quantile(tib.c$Flores.r,0.75)
## 75%
## 17
v1=c("Biomasa","Flores.r");v2=c(4.53,17);
tib.c %>%
filter(.[v1[1]]>v2[1],
.[v1[2]]>v2[2])
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion
## 1 5.78 18 6 298 Presente S FO
## 2 6.61 19 9 196 Presente S FO
## 3 6.15 18 6 108 Presente S FO
## 4 4.84 18 11 91 Ausente S FO
## 5 5.16 19 11 72 Presente S FI
## 6 5.16 19 11 130 Presente S FO
## 7 5.62 18 6 125 Presente S FI
## 8 5.77 19 10 210 Presente PA FO
## 9 4.92 18 10 160 Presente PA FO
## 10 4.76 18 14 176 Ausente MA FO
## 11 5.31 18 10 130 Presente MA FO
## 12 6.48 18 13 118 Presente MA FI
## 13 5.38 19 14 278 Presente MA FO
## 14 4.71 19 8 41 Presente MA FO
## 15 5.49 20 2 28 Presente MA FI
## 16 6.39 18 8 62 Presente MA FI
## 17 5.51 19 9 167 Presente MA FO
## 18 6.16 19 5 267 Presente MA FI
## 19 5.07 18 10 164 Ausente MA FO
## 20 6.64 18 13 221 Ausente MA FI
tib.e = tib.c%>%
mutate(Biomasa_z = (Biomasa - mean(Biomasa)) / sd(Biomasa),
Flores.r_min=(Flores.r-min(Flores.r))/range(Flores.r),
Flores.d_min=(Flores.d-min(Flores.d))/range(Flores.d),
Hojas.d_min=(Hojas.d-min(Hojas.d)))
head(tib.e)
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion Biomasa_z
## 1 4.27 15 14 104 Presente S FI -0.9596284
## 2 4.70 17 13 103 Ausente S FI -0.4387824
## 3 5.76 16 14 95 Presente S FO 0.8451634
## 4 6.48 14 16 4 Presente S FO 1.7172776
## 5 5.78 18 6 298 Presente S FO 0.8693888
## 6 4.00 15 8 225 Presente S FI -1.2866712
## Flores.r_min Flores.d_min Hojas.d_min
## 1 0.2500000 6.0000000 100
## 2 0.2500000 0.6111111 99
## 3 0.3333333 6.0000000 91
## 4 0.1000000 0.7777778 0
## 5 0.5000000 2.0000000 294
## 6 0.1500000 0.3333333 221
Como ya hemos usado varias funciones, en los ejercicios posteriores se omitirán funciones antes evaluadas y solo se mencionarán aquellas que no se hayan usado.
tib.c %>%
mutate(div_flores=Flores.r/Flores.d) %>%
head
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion div_flores
## 1 4.27 15 14 104 Presente S FI 1.071429
## 2 4.70 17 13 103 Ausente S FI 1.307692
## 3 5.76 16 14 95 Presente S FO 1.142857
## 4 6.48 14 16 4 Presente S FO 0.875000
## 5 5.78 18 6 298 Presente S FO 3.000000
## 6 4.00 15 8 225 Presente S FI 1.875000
tib.c %>%
mutate(div_flores=Flores.r/Flores.d) %>%
group_by(Plaga) %>%
mutate( rangomin= min_rank(desc(div_flores))) %>%
head()
## # A tibble: 6 x 9
## # Groups: Plaga [2]
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion div_flores
## <dbl> <int> <int> <int> <chr> <fct> <chr> <dbl>
## 1 4.27 15 14 104 Presente S FI 1.07
## 2 4.7 17 13 103 Ausente S FI 1.31
## 3 5.76 16 14 95 Presente S FO 1.14
## 4 6.48 14 16 4 Presente S FO 0.875
## 5 5.78 18 6 298 Presente S FO 3
## 6 4 15 8 225 Presente S FI 1.88
## # ... with 1 more variable: rangomin <int>
tib.e %>%
rename(Fl.en.rama=Flores.r,
Fl.despre=Flores.d,
minmax.Fl.en.rama=Flores.r_min,
minmax.Fl.despre=Flores.d_min) %>%
head()
## Biomasa Fl.en.rama Fl.despre Hojas.d Plaga Estatus Fertilizacion
## 1 4.27 15 14 104 Presente S FI
## 2 4.70 17 13 103 Ausente S FI
## 3 5.76 16 14 95 Presente S FO
## 4 6.48 14 16 4 Presente S FO
## 5 5.78 18 6 298 Presente S FO
## 6 4.00 15 8 225 Presente S FI
## Biomasa_z minmax.Fl.en.rama minmax.Fl.despre Hojas.d_min
## 1 -0.9596284 0.2500000 6.0000000 100
## 2 -0.4387824 0.2500000 0.6111111 99
## 3 0.8451634 0.3333333 6.0000000 91
## 4 1.7172776 0.1000000 0.7777778 0
## 5 0.8693888 0.5000000 2.0000000 294
## 6 -1.2866712 0.1500000 0.3333333 221
tib.e %>%
rename_with(toupper) %>%
head
## BIOMASA FLORES.R FLORES.D HOJAS.D PLAGA ESTATUS FERTILIZACION BIOMASA_Z
## 1 4.27 15 14 104 Presente S FI -0.9596284
## 2 4.70 17 13 103 Ausente S FI -0.4387824
## 3 5.76 16 14 95 Presente S FO 0.8451634
## 4 6.48 14 16 4 Presente S FO 1.7172776
## 5 5.78 18 6 298 Presente S FO 0.8693888
## 6 4.00 15 8 225 Presente S FI -1.2866712
## FLORES.R_MIN FLORES.D_MIN HOJAS.D_MIN
## 1 0.2500000 6.0000000 100
## 2 0.2500000 0.6111111 99
## 3 0.3333333 6.0000000 91
## 4 0.1000000 0.7777778 0
## 5 0.5000000 2.0000000 294
## 6 0.1500000 0.3333333 221
rename_with(tib.e,~tolower(gsub(".","_",.x,fixed=TRUE))) %>% head
## biomasa flores_r flores_d hojas_d plaga estatus fertilizacion biomasa_z
## 1 4.27 15 14 104 Presente S FI -0.9596284
## 2 4.70 17 13 103 Ausente S FI -0.4387824
## 3 5.76 16 14 95 Presente S FO 0.8451634
## 4 6.48 14 16 4 Presente S FO 1.7172776
## 5 5.78 18 6 298 Presente S FO 0.8693888
## 6 4.00 15 8 225 Presente S FI -1.2866712
## flores_r_min flores_d_min hojas_d_min
## 1 0.2500000 6.0000000 100
## 2 0.2500000 0.6111111 99
## 3 0.3333333 6.0000000 91
## 4 0.1000000 0.7777778 0
## 5 0.5000000 2.0000000 294
## 6 0.1500000 0.3333333 221
Entre las opciones interesantes para realizar estadísticas descriptivas esta la función summarise(), la cual usaremos en la siguiente actividad:
tib.i %>%
select(Biomasa) %>%
summarise(media=mean(Biomasa,na.rm=TRUE),n.datos=n())
## media n.datos
## 1 4.977079 90
tib.i %>%
select(Biomasa,Fertilizacion) %>%
group_by(Fertilización=Fertilizacion)%>%
summarise(media=mean(Biomasa,na.rm=TRUE),n.datos=n())
## # A tibble: 2 x 3
## Fertilización media n.datos
## <chr> <dbl> <int>
## 1 FI 4.84 46
## 2 FO 5.12 44
tib.i %>%
select(Biomasa, Fertilizacion) %>%
group_by (Fertilización=Fertilizacion) %>%
summarise(C1=quantile(Biomasa,0.10,na.rm=TRUE),
C2= quantile(Biomasa,0.20,na.rm=TRUE),
C3=quantile(Biomasa, 0.30,na.rm=TRUE),
C4=quantile(Biomasa, 0.40,na.rm=TRUE),
C5=quantile(Biomasa, 0.50,na.rm=TRUE))
## # A tibble: 2 x 6
## Fertilización C1 C2 C3 C4 C5
## <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 FI 3.64 4.13 4.58 4.66 4.86
## 2 FO 3.97 4.47 4.84 4.89 5.16
tib.i %>%
select(Biomasa,Fertilizacion,Plaga) %>%
group_by(Fertilización=Fertilizacion,Plaga=Plaga) %>%
summarise(Media=mean(Biomasa,na.rm=TRUE),
Mediana=median(Biomasa,na.rm=TRUE),
Máx=max(Biomasa,na.rm=TRUE),
Mín=min(Biomasa,na.rm=TRUE),
Des.tip=sd(Biomasa,na.rm=TRUE),
Des.media=mean(abs(Biomasa-mean(Biomasa)),na.rm=TRUE),
Media.T=mean(Biomasa,trim=0.5,na.rm=TRUE),
Varianza=var(Biomasa,na.rm=TRUE)) %>%
head
## `summarise()` has grouped output by 'Fertilización'. You can override using the `.groups` argument.
## # A tibble: 4 x 10
## # Groups: Fertilización [2]
## Fertilización Plaga Media Mediana Máx Mín Des.tip Des.media Media.T
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 FI Ausente 5.06 4.72 6.59 4.48 0.610 0.478 4.72
## 2 FI Presente 4.75 5.03 6.48 2.94 0.919 0.763 5.03
## 3 FO Ausente 5.05 4.99 5.99 3.97 0.577 NaN 4.99
## 4 FO Presente 5.15 5.16 6.54 3.63 0.869 0.695 5.16
## # ... with 1 more variable: Varianza <dbl>
tib.i %>%
select(Biomasa,Fertilizacion,Plaga,Estatus) %>% group_by(Fertilización=Fertilizacion,Plaga=Plaga,Estatus) %>%
summarise(Media=mean(Biomasa),
Mediana=median(Biomasa),
Máx=max(Biomasa),
Mín=min(Biomasa),
Des.tip=sd(Biomasa),
Des.media=mean(abs(Biomasa-mean(Biomasa))),
Media.T=mean(Biomasa,trim=0.5),
Varianza=var(Biomasa)) %>%
filter(Estatus=="S")
## `summarise()` has grouped output by 'Fertilización', 'Plaga'. You can override using the `.groups` argument.
## # A tibble: 4 x 11
## # Groups: Fertilización, Plaga [4]
## Fertilización Plaga Estatus Media Mediana Máx Mín Des.tip Des.media
## <chr> <chr> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 FI Ausente S 4.72 4.66 4.91 4.66 0.109 0.0768
## 2 FI Presente S 4.37 4.39 5.32 3.55 0.640 0.556
## 3 FO Ausente S 5.42 5.42 5.99 4.84 0.664 0.575
## 4 FO Presente S 5.54 5.38 6.48 4.51 0.650 0.517
## # ... with 2 more variables: Media.T <dbl>, Varianza <dbl>
tib.i %>%
select(Biomasa,Fertilizacion,Plaga,Estatus) %>%
group_by(Fertilización=Fertilizacion,Plaga=Plaga,Estatus) %>%
summarise(Media=mean(Biomasa),
Mediana=median(Biomasa),
Máx=max(Biomasa),
Mín=min(Biomasa),
Des.tip=sd(Biomasa),
Des.media=mean(abs(Biomasa-mean(Biomasa))),
Media.T=mean(Biomasa,trim=0.5),
Varianza=var(Biomasa)) %>%
filter(Estatus=="S") %>% drop_na()
## `summarise()` has grouped output by 'Fertilización', 'Plaga'. You can override using the `.groups` argument.
## # A tibble: 4 x 11
## # Groups: Fertilización, Plaga [4]
## Fertilización Plaga Estatus Media Mediana Máx Mín Des.tip Des.media
## <chr> <chr> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 FI Ausente S 4.72 4.66 4.91 4.66 0.109 0.0768
## 2 FI Presente S 4.37 4.39 5.32 3.55 0.640 0.556
## 3 FO Ausente S 5.42 5.42 5.99 4.84 0.664 0.575
## 4 FO Presente S 5.54 5.38 6.48 4.51 0.650 0.517
## # ... with 2 more variables: Media.T <dbl>, Varianza <dbl>
tib.i %>%
select(Biomasa,Fertilizacion,Plaga,Estatus) %>%
group_by(Fertilización=Fertilizacion,Plaga=Plaga,Estatus) %>%
summarise(Media=mean(Biomasa),
Mediana=median(Biomasa),
Máx=max(Biomasa),
Mín=min(Biomasa),
Des.tip=sd(Biomasa),
Des.media=mean(abs(Biomasa-mean(Biomasa))),
Media.T=mean(Biomasa,trim=0.5),
Varianza=var(Biomasa)) %>%
filter(Estatus %in% c("MA","PA")) %>%
drop_na()
## `summarise()` has grouped output by 'Fertilización', 'Plaga'. You can override using the `.groups` argument.
## # A tibble: 7 x 11
## # Groups: Fertilización, Plaga [4]
## Fertilización Plaga Estatus Media Mediana Máx Mín Des.tip Des.media
## <chr> <chr> <fct> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 FI Ausente PA 5.26 5.23 5.69 4.48 0.495 0.341
## 2 FI Ausente MA 5.31 4.72 6.59 4.62 1.11 0.853
## 3 FI Presente PA 5.08 5.29 5.8 3.74 0.697 0.537
## 4 FI Presente MA 4.76 5.15 6.48 2.94 1.20 0.989
## 5 FO Ausente PA 4.44 4.44 4.9 3.97 0.465 0.311
## 6 FO Presente PA 4.75 4.92 5.85 3.63 0.988 0.895
## 7 FO Presente MA 5.24 4.89 6.54 4.43 0.793 0.649
## # ... with 2 more variables: Media.T <dbl>, Varianza <dbl>
tib.i %>%
complete.cases() %>% sum()
## [1] 88
tib.i_complete <- tib.i[complete.cases(tib.i),]
tib.i_complete
## Biomasa Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion
## 1 5.13 15 12 251 Presente PA FI
## 2 4.11 16 12 83 Presente S FI
## 3 3.63 15 12 257 Presente PA FO
## 4 2.94 16 12 32 Presente MA FI
## 5 4.76 18 14 176 Ausente MA FO
## 6 4.89 17 13 192 Presente MA FO
## 7 5.16 19 11 130 Presente S FO
## 8 3.63 15 12 257 Presente PA FO
## 9 5.06 13 11 220 Presente MA FI
## 10 4.89 17 13 192 Presente MA FO
## 11 5.49 20 2 28 Presente MA FI
## 12 4.35 17 8 127 Presente MA FI
## 13 5.13 15 12 251 Presente PA FI
## 14 5.23 15 10 244 Ausente PA FI
## 16 5.78 17 17 155 Presente MA FI
## 17 4.70 17 13 103 Ausente S FI
## 18 4.87 13 6 107 Presente MA FO
## 19 5.16 19 11 130 Presente S FO
## 20 6.54 15 10 204 Presente MA FO
## 21 5.76 16 14 95 Presente S FO
## 22 5.16 19 11 130 Presente S FO
## 23 4.90 16 12 205 Ausente PA FO
## 24 5.99 15 9 105 Ausente S FO
## 25 5.25 16 12 217 Presente MA FI
## 26 6.48 14 16 4 Presente S FO
## 27 5.85 15 10 8 Presente PA FO
## 28 6.48 14 16 4 Presente S FO
## 29 5.61 17 8 195 Presente PA FI
## 31 5.38 13 13 258 Presente PA FI
## 32 5.26 17 14 129 Presente PA FO
## 33 3.75 18 15 56 Presente S FI
## 34 6.59 17 11 167 Ausente MA FI
## 35 5.38 15 16 79 Presente S FO
## 36 4.89 17 13 192 Presente MA FO
## 37 3.74 15 7 26 Presente PA FI
## 38 4.13 17 14 141 Presente S FI
## 39 4.66 17 11 40 Ausente S FI
## 40 4.00 17 5 119 Presente PA FI
## 41 4.55 13 9 47 Presente PA FI
## 42 5.72 13 11 4 Presente MA FI
## 43 6.12 14 13 41 Presente MA FO
## 44 4.66 13 16 40 Presente S FI
## 45 5.99 15 9 105 Ausente S FO
## 46 4.82 15 5 112 Presente S FI
## 47 4.51 18 9 191 Presente S FO
## 48 5.69 14 11 82 Ausente PA FI
## 49 5.32 16 14 241 Presente S FI
## 50 4.44 17 13 181 Ausente PA FO
## 51 4.62 17 10 80 Ausente MA FI
## 52 4.91 17 13 284 Ausente S FI
## 53 3.12 17 14 58 Presente MA FI
## 54 5.31 18 10 130 Presente MA FO
## 55 5.76 16 14 95 Presente S FO
## 56 5.49 20 2 28 Presente MA FI
## 57 4.84 18 11 91 Ausente S FO
## 58 5.81 12 15 281 Presente PA FO
## 59 5.23 15 10 244 Ausente PA FI
## 60 3.63 15 12 257 Presente PA FO
## 61 4.66 17 11 40 Ausente S FI
## 62 4.43 14 9 185 Presente MA FO
## 63 5.80 16 17 178 Presente PA FI
## 64 4.84 18 11 91 Ausente S FO
## 65 3.97 19 6 95 Presente PA FO
## 66 3.55 16 10 288 Presente S FI
## 67 5.28 15 12 287 Ausente MA FO
## 68 5.29 16 16 12 Presente PA FI
## 69 5.69 14 11 82 Ausente PA FI
## 70 5.03 17 8 166 Presente S FI
## 71 3.97 16 10 116 Ausente PA FO
## 72 5.28 15 12 287 Ausente MA FO
## 73 5.81 12 15 281 Presente PA FO
## 74 6.48 18 13 118 Presente MA FI
## 75 4.43 14 9 185 Presente MA FO
## 76 3.97 19 6 95 Presente PA FO
## 77 5.77 19 10 210 Presente PA FO
## 78 5.28 15 12 287 Ausente MA FO
## 79 5.07 18 10 164 Ausente MA FO
## 80 2.94 16 12 32 Presente MA FI
## 81 5.80 16 17 178 Presente PA FI
## 82 4.82 15 5 112 Presente S FI
## 83 4.48 16 16 52 Ausente PA FI
## 84 5.47 17 8 244 Presente PA FI
## 85 4.72 17 4 235 Ausente MA FI
## 86 4.92 18 10 160 Presente PA FO
## 87 4.68 14 13 151 Presente MA FO
## 88 3.55 16 10 288 Presente S FI
## 89 4.66 17 11 40 Ausente S FI
## 90 4.53 15 12 120 Presente MA FI
tib.i2=tib.i[,-(2:3),drop=FALSE]
head(tib.i2)
## Biomasa Hojas.d Plaga Estatus Fertilizacion
## 1 5.13 251 Presente PA FI
## 2 4.11 83 Presente S FI
## 3 3.63 257 Presente PA FO
## 4 2.94 32 Presente MA FI
## 5 4.76 176 Ausente MA FO
## 6 4.89 192 Presente MA FO
tib.c %>%
select(contains("d")) %>%
head
## Flores.d Hojas.d
## 1 14 104
## 2 13 103
## 3 14 95
## 4 16 4
## 5 6 298
## 6 8 225
tib.c %>%
select(!everything("Flores"),Biomasa) %>%
head
## Flores.r Flores.d Hojas.d Plaga Estatus Fertilizacion Biomasa
## 1 15 14 104 Presente S FI 4.27
## 2 17 13 103 Ausente S FI 4.70
## 3 16 14 95 Presente S FO 5.76
## 4 14 16 4 Presente S FO 6.48
## 5 18 6 298 Presente S FO 5.78
## 6 15 8 225 Presente S FI 4.00