Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Tilastotiede ja R tutuksi
- #Helsingin yliopisto, Matematiikan ja tilastotieteen laitos
- #Harjoitus 2
- ###################Tehtävä 6#######################
- #a
- numero<-c(1,2,3,4,5,6)
- rikos<-c("Huumausainerikos","Väärentäminen","Huumausainerikos","Kidnappaus","Ryöstö","Ryöstö")
- rangaistus<-c(44,30,52,240,120,96)
- vangittu<-c(24,12,26,96,52,49)
- #b
- numero<-as.character(numero)
- rikos<-as.factor(rikos)
- #c
- taulu<-data.frame(numero,rikos,rangaistus,vangittu,
- stringsAsFactors=FALSE)
- str(taulu)
- ###################Tehtävä 7#######################
- #a
- install.packages("MASS")
- library("MASS")
- str(survey)
- #237 riviä, 12 saraketta
- #b
- mean(survey$Height,na.rm=TRUE)
- max(survey$Height,na.rm=TRUE)
- min(survey$Height,na.rm=TRUE)
- #c
- mean(survey$Height[survey$Sex=="Male"],na.rm = TRUE)
- mean(survey$Height[survey$Sex=="Female"],na.rm = TRUE)
- ###################Tehtävä 8#######################
- #a
- Age2<-floor(survey$Age)
- survey$Age2<-Age2
- #b
- osa<-survey[survey$Sex=="Female"&survey$Age2==17,]
- #c
- hist(osa$Height)
- ###################Tehtävä 9#######################
- #a
- length(survey$Pulse[is.na(survey$Pulse)])
- #b
- length(na.exclude(survey$Pulse[survey$Pulse<45|survey$Pulse>100]))
- #c
- boxplot(survey$Pulse~survey$Sex)
- #vastaajista naisilla on korkeampi mediaanipulssi
- ###################Tehtävä 10#######################
- #a
- table(survey$Fold)
- #R on L
- #b
- taulukko<-table(survey$Fold,survey$W.Hnd)
- taulukko
- #L on R
- #c
- prop.table(taulukko,2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement