1
$\begingroup$

My table of data looks like this image (but with many more lines):

enter image description here

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?

$\endgroup$

2 Answers 2

1
$\begingroup$

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()
$\endgroup$
0
$\begingroup$

Something like this for instance:

library(plyr)
ddply(data,'region',function(x) {mean(x$age)})
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.