Statistics and Statistical Programming (Winter 2017)/R lecture outline: Week 6

From CommunityData
Jump to navigation Jump to search
  • the cut() function: cut(airquality$Temp, quantile(airquality$temp))
  • tabular data: many ways to create it
    • input it directly (using the matrix command, which I used in week 2 or using rbind):
genpol <- as.matrix(rbind(c(762, 327, 468), c(484, 239, 477)))
dimnames(gen.pol) <- list(gender = c("F", "M")
party = c("Democrat","Independent", "Republican"))
  • more ways to create tabular data:
    • with tapply: tapply(warpbreaks$breaks, list(warpbreaks$wool, warpbreaks$tension), sum)
    • creating it with table(): table(cut(airquality$Temp, quantile(airquality$Temp)), airquality$Month)
  • once we have tables, we can look at them: margin.table() is fast; prop.table() is super useful
  • chisq tests: chisq.test()
    • looking into the chisq.test() object; i often use TAB; names() is also good
  • debugging code
    • print line debugging
    • running the inside of functions