My table of data looks like this image (but with many more lines):
I want to be able to find the mean age of each region, so the mean age for region SSC20790 and so on. I believe I can use the dplyr
package?
Yes, the dplyr package can be used to calculate that:
mean_by_region <- your_data %>%
group_by(region) %>%
mutate(mean_age=mean(age,na.rm=T)) %>%
data.frame()
Something like this for instance:
library(plyr)
ddply(data,'region',function(x) {mean(x$age)})