#slide 27 grade[order(grade$Chinese),] #sort by Chinese asc grade[order(-grade$Chinese),] #sort by Chinese desc
#slide 28
#or use attach attach(grade) #sort by chinese asc grade[order(Chinese),] #sort by chinese asc, English desc grade[order(Chinese,-English),] detach(grade)
#slide 30 attach(total) #compute the average grade by class aggregate(total[c("Chinese","Math","English","Science")], by=list(class), FUN=mean) #compute the average grade by class and gender aggregate(total[c("Chinese","Math","English","Science")], by=list(class, gender), FUN=mean) detach(total)
#slide 34 for(i in1:10) { print(i) }
#slide 35 x <- matrix(1:6, nrow=2, ncol=3, byrow=T) for(i in1:nrow(x)){ for (j in1:ncol(x)){ print(paste(i,j,x[i,j])) } }