Aggregation functions

If, say, we were interested in finding the aggregate values of each Region of the US, we could use aggregate to find the cumulative values on a per region basis. To find the min, max, and mean of each column aggregated by region, we will first add the region value to our DataFrame:

# aggregate 
 
state$Region <- state.region 
ncol(state) 
aggregate(state[,-c(9,10)], by=list(state$Region), mean, na.rm = T) 

Following is the output:

Get Hands-On Data Science with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.