September 2017
Beginner to intermediate
560 pages
25h 18m
English
We calculate the number of rows and the mean mpg of the data frame grouped by cylinders. The following command shows the output when summarize is used:
> ddply(auto, .(cylinders), summarize, freq=length(cylinders), meanmpg=mean(mpg)) cylinders freq meanmpg 1 3cyl 4 20.55000 2 4cyl 204 29.28676 3 5cyl 3 27.36667 4 6cyl 84 19.98571 5 8cyl 103 14.96311
The following command creates histograms of mpg for each cylinder:
> par(mfrow = c(1,2))> d_ply(auto,"cylinders",summarise, hist(mpg,xlab="Miles per Gallon",main="Histogram of Miles per Gallon",breaks=5))
The following plot is the output of preceding command:
Read now
Unlock full access