Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #Tilastotiede ja R tutuksi
  2. #Helsingin yliopisto, Matematiikan ja tilastotieteen laitos
  3. #Harjoitus 2
  4.  
  5. ###################Tehtävä 6#######################
  6. #a
  7.  
  8. numero<-c(1,2,3,4,5,6)
  9.  
  10. rikos<-c("Huumausainerikos","Väärentäminen","Huumausainerikos","Kidnappaus","Ryöstö","Ryöstö")
  11.  
  12. rangaistus<-c(44,30,52,240,120,96)
  13.  
  14. vangittu<-c(24,12,26,96,52,49)
  15.  
  16. #b
  17.  
  18. numero<-as.character(numero)
  19.  
  20. rikos<-as.factor(rikos)
  21.  
  22. #c
  23.  
  24. taulu<-data.frame(numero,rikos,rangaistus,vangittu,
  25. stringsAsFactors=FALSE)
  26.  
  27. str(taulu)
  28.  
  29. ###################Tehtävä 7#######################
  30. #a
  31.  
  32. install.packages("MASS")
  33.  
  34. library("MASS")
  35.  
  36. str(survey)
  37.  
  38. #237 riviä, 12 saraketta
  39.  
  40. #b
  41.  
  42. mean(survey$Height,na.rm=TRUE)
  43.  
  44. max(survey$Height,na.rm=TRUE)
  45.  
  46. min(survey$Height,na.rm=TRUE)
  47.  
  48. #c
  49.  
  50. mean(survey$Height[survey$Sex=="Male"],na.rm = TRUE)
  51.  
  52. mean(survey$Height[survey$Sex=="Female"],na.rm = TRUE)
  53.  
  54. ###################Tehtävä 8#######################
  55. #a
  56.  
  57. Age2<-floor(survey$Age)
  58.  
  59. survey$Age2<-Age2
  60.  
  61. #b
  62.  
  63. osa<-survey[survey$Sex=="Female"&survey$Age2==17,]
  64.  
  65. #c
  66.  
  67. hist(osa$Height)
  68.  
  69. ###################Tehtävä 9#######################
  70. #a
  71.  
  72. length(survey$Pulse[is.na(survey$Pulse)])
  73.  
  74. #b
  75.  
  76. length(na.exclude(survey$Pulse[survey$Pulse<45|survey$Pulse>100]))
  77.  
  78. #c
  79.  
  80. boxplot(survey$Pulse~survey$Sex)
  81.  
  82. #vastaajista naisilla on korkeampi mediaanipulssi
  83.  
  84. ###################Tehtävä 10#######################
  85. #a
  86.  
  87. table(survey$Fold)
  88.  
  89. #R on L
  90.  
  91. #b
  92.  
  93. taulukko<-table(survey$Fold,survey$W.Hnd)
  94.  
  95. taulukko
  96.  
  97. #L on R
  98.  
  99. #c
  100.  
  101. prop.table(taulukko,2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement