### number of Facebook friends ### # first set fbf = c(546,388,724,269,113,467,682,178,149,382,196) fbf2 = c(546,388,5439,269,11,467,682,178,149,382,196) # sort in ascending order sort(fbf) # median median(fbf) # mean mean(fbf) # boxplot in red boxplot(fbf,col=2) # alternative col="red" # boxplot in blue boxplot(fbf2,col=4) # alternative col="blue" # plants and animals # install the package languageR provided by Harald Baayen install.packages("languageR") # after installing it library(languageR) # a set of R objects are automatically loaded. This time you need 'ratings'. # define a logical vector: plants = ratings$Class == "plant" # then create a table with the frequencies table(ratings$Length[plants]) pie(table(ratings$Length[plants])) # since all non-plants are animals, the reverse is true for animals. # ! means "not true" table(ratings$Length[!plants]) pie(table(ratings$Length[!plants])) # barplots for plants with raw values barplot(table(ratings$Length[plants])) # barplots for plants with percentages barplot(table(ratings$Length[plants])) # barplots with both classes with some fancy modifications barplot(table(ratings$Class,ratings$Length)/81*100,beside=T,col=c(4,3),ylim=c(0,20),cex.axis=1.3,ylab="frequency (%)",cex.lab=1.3) # histogram hist(ratings$Length[plants]) # density line plot(density(ratings$Length[plants]))