Statistics and Statistical Programming (Winter 2017)/R lecture outline: Week 6: Difference between revisions
From CommunityData
No edit summary |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 5: | Line 5: | ||
dimnames(gen.pol) <- list(gender = c("F", "M") | dimnames(gen.pol) <- list(gender = c("F", "M") | ||
party = c("Democrat","Independent", "Republican")) | party = c("Democrat","Independent", "Republican")) | ||
* more ways to create tabular data: | |||
** with tapply: tapply(warpbreaks$breaks, list(warpbreaks$wool, warpbreaks$tension), sum) | ** with tapply: tapply(warpbreaks$breaks, list(warpbreaks$wool, warpbreaks$tension), sum) | ||
** creating it with table(): table(cut(airquality$Temp, quantile(airquality$Temp)), airquality$Month) | ** 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 | * once we have tables, we can look at them: margin.table() is fast; prop.table() is super useful | ||
* chisq tests: chisq.test() | * chisq tests: chisq.test() | ||
** looking into the chisq.test() object; i often use TAB | ** looking into the chisq.test() object; i often use TAB; names() is also good | ||
* debugging code | * debugging code | ||
** print line debugging | ** print line debugging | ||
** running the inside of functions | ** running the inside of functions |
Latest revision as of 04:06, 8 February 2017
- 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