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?
Data Science Stack Exchange is a question and answer site for Data science professionals, Machine Learning specialists, and those interested in learning more about the field. It only takes a minute to sign up.
Sign up to join this communitySomething like this for instance:
library(plyr)
ddply(data,'region',function(x) {mean(x$age)})
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()