# R script to illustrate some summaries of categorical data. stu.data=read.table("student_survey.txt",header=TRUE) stu.data stu.data$gender # Can use columns of data frame as vectors this # way if data frame is not attached. table(stu.data$gender) barplot(table(stu.data$gender),xlim=c(0,1),width=.1,space=2) stu.table=table(stu.data$gender,stu.data$political_affiliation) stu.table margin.table(stu.table) # sums counts in the table. margin.table(stu.table,margin=1) # margin=1 sums rows. margin.table(stu.table,margin=2) # margin=2 sums columns. barplot(stu.table) windows() # Opens new graphics window; use quartz() for Mac, X11() for Unix. mosaicplot(stu.table) stu.mv.data=subset(stu.data,stu.data$gender=="m" & stu.data$vegetarian=="y") stu.mv.data