Comenzamos instalando cargando la librería
# install.packages("tables")
library( tables )
## Warning: package 'tables' was built under R version 3.3.3
## Warning: package 'Hmisc' was built under R version 3.3.3
## Warning: package 'survival' was built under R version 3.3.3
## Warning: package 'ggplot2' was built under R version 3.3.3
Leemos el conjunto de datos biom2003Anotado.RData, que contiene los datos con las variables categóricas etiquetadas
load( "biom2003Anotado.RData" )
Comprobamos que el conjunto de datos es correcto
head( df ); str( df )
## Grupo Peso Altura Pie Hombros Brazos Caderas Sexo Ojos Tipo
## 1 1 60 163 37 41 68 95 mujer oscuros delgado
## 2 1 52 166 37 37 70 87 mujer claros atlético
## 3 1 61 172 39 39 69 91 mujer claros atlético
## 4 1 73 181 43 50 78 101 hombre claros atlético
## 5 1 53 172 39 39 72 89 mujer oscuros atlético
## 6 1 63 169 40 37 66 96 mujer claros atlético
## 'data.frame': 98 obs. of 10 variables:
## $ Grupo : int 1 1 1 1 1 1 1 1 1 1 ...
## $ Peso : int 60 52 61 73 53 63 55 56 64 72 ...
## $ Altura : int 163 166 172 181 172 169 170 169 180 178 ...
## $ Pie : int 37 37 39 43 39 40 38 42 41 43 ...
## $ Hombros: int 41 37 39 50 39 37 43 40 41 43 ...
## $ Brazos : int 68 70 69 78 72 66 74 70 78 80 ...
## $ Caderas: int 95 87 91 101 89 96 97 90 101 97 ...
## $ Sexo : Factor w/ 2 levels "mujer","hombre": 1 1 1 2 1 1 1 2 1 2 ...
## $ Ojos : Factor w/ 2 levels "oscuros","claros": 1 2 2 2 1 2 2 2 1 1 ...
## $ Tipo : Factor w/ 3 levels "atlético","delgado",..: 2 1 1 1 1 1 1 1 1 1 ...
Una vez tenemos una lectura adecuada de la tabla de datos, podemos pasar a realizar una serie de descripciones y tabulaciones.
names(df)
[1] “Grupo” “Peso” “Altura” “Pie” “Hombros” “Brazos” “Caderas” [8] “Sexo” “Ojos” “Tipo”
tt=tabular(Tipo~Sexo, data=df)
html(tt,
options = htmloptions(HTMLcaption="Pie de tabla", pad = TRUE))
| Sexo | ||
|---|---|---|
| Tipo | mujer | hombre |
| atlético | 49 | 18 |
| delgado | 14 | 3 |
| pesado | 3 | 11 |
t=table(df$Sexo);t
mujer hombre 66 32
tt=tabular(~Sexo, data=df)
html(tt,
options = htmloptions(HTMLcaption="Pie de tabla", pad = TRUE))
| Sexo | ||
|---|---|---|
| mujer | hombre | |
| 66 | 32 | |
addmargins(t)
mujer hombre Sum 66 32 98
tt=tabular(~Sexo+1, data=df)
html(tt,
options = htmloptions(HTMLcaption="Pie de tabla", pad = TRUE))
| Sexo | |||
|---|---|---|---|
| mujer | hombre | All | |
| 66 | 32 | 98 | |
Alturamean(df$Altura)
[1] 169.7143
median(df$Altura)
[1] 170
sd(df$Altura)
[1] 8.729615
tt=tabular(~(Altura*mean)+(Altura*median)+(Altura*sd), data=df)
html(tt,
options = htmloptions(HTMLcaption="Pie de tabla", pad = TRUE))
| Altura | Altura | Altura | |
|---|---|---|---|
| mean | median | sd | |
| 169.7 | 170 | 8.73 |
tt=tabular(Ojos~(Peso*mean), data=df)
html(tt,
options = htmloptions(HTMLcaption="Pie de tabla", pad = TRUE))
| Peso | |
|---|---|
| Ojos | mean |
| oscuros | 61.72 |
| claros | 63.49 |
tt=tabular(Sexo * Tipo ~ Peso * mean, data = df )
html(tt,
options = htmloptions(HTMLcaption="Pie de tabla", pad = TRUE))
| Peso | ||
|---|---|---|
| Sexo | Tipo | mean |
| mujer | atlético | 56.33 |
| delgado | 65.93 | |
| pesado | 59.00 | |
| hombre | atlético | 68.61 |
| delgado | 80.67 | |
| pesado | 77.55 |
Por último, deja traza de la sesión:
sessionInfo()
## R version 3.3.2 (2016-10-31)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 14393)
##
## locale:
## [1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252
## [3] LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C
## [5] LC_TIME=Spanish_Spain.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] tables_0.8 Hmisc_4.0-2 ggplot2_2.2.1 Formula_1.2-1
## [5] survival_2.41-2 lattice_0.20-34
##
## loaded via a namespace (and not attached):
## [1] Rcpp_0.12.9 RColorBrewer_1.1-2 plyr_1.8.4
## [4] base64enc_0.1-3 tools_3.3.2 rpart_4.1-10
## [7] digest_0.6.12 evaluate_0.10 tibble_1.2
## [10] gtable_0.2.0 htmlTable_1.9 checkmate_1.8.2
## [13] Matrix_1.2-7.1 yaml_2.1.14 gridExtra_2.2.1
## [16] stringr_1.2.0 knitr_1.15.1 cluster_2.0.5
## [19] htmlwidgets_0.8 rprojroot_1.2 grid_3.3.2
## [22] nnet_7.3-12 data.table_1.10.4 foreign_0.8-67
## [25] rmarkdown_1.3 latticeExtra_0.6-28 magrittr_1.5
## [28] backports_1.0.5 scales_0.4.1 htmltools_0.3.5
## [31] splines_3.3.2 assertthat_0.1 colorspace_1.3-2
## [34] stringi_1.1.2 acepack_1.4.1 lazyeval_0.2.0
## [37] munsell_0.4.3