syc<-SDaA::syc
Pregunta 1
1)Recodifique la variable ethnicty, que toma los valores de 1 si el individuo es Hispano ,0 si no lo es y 9 si el valor no esta disponible
recod1 <-ifelse(syc$ethnicty == "notHispanic",0,
+ ifelse(syc$ethnicty == "hispanic",1,9))
table(recod1)
## recod1
## 0 1
## 2146 467
Pregunta 2
2)construya una tabla de frecuencias relativas cruzadas para la variable ethnicty y sex
table(syc$ethnicty,syc$sex)
##
## male female
## hispanic 430 37
## notHispanic 2035 111
Pregunta 3
3)cálcule la varianza de la edad agrupando por la variable ethnicty
tapply(syc$age,syc$ethnicty ,var)
## hispanic notHispanic
## 4.131898 3.447539
Pregunta 4
4) Construya un gráfico de barra comparativo para las variables ethnicty y sex
barplot(table(syc$ethnicty, syc$sex, exclude = NA),col=topo.colors(3),beside = T)

Pregunta 5
5) modificar el gráfico de barra comparativo en ggplot2 con porcentajes en vez de conteos
library("ggplot2")
ggplot(syc, aes(sex, fill= ethnicty)) + geom_bar(aes(y = (..count..)/sum(..count..)), position = "dodge")+ ylab("Porcentaje")
