I have a dataset that has a range of IDs and activities, and a bunch of columns of observations for each combination of ID and activity. I'd like to take the average of each observation, but since there's hundreds and hundreds of observations, I'm unclear how to proceed.
Example data:
id,activity,obs1,obs2,obs3
1,1,325,6432,5432
1,2,321,214,2143
1,3,3652,123,123
2,1,5321,123,643
2,2,4312,4321,432
2,3,522,123,321
1,1,532,765,8976
1,2,142,865,5445
1,3,643,654,53
2,1,756,765,7865
2,2,876,654,976
2,3,6754,765,987
What I've tried so far:
library(dplyr)
example <- read.table("clipboard",sep=",",header=T)
group <- group_by(example,id,activity)
summarize(group, mobs1=mean(obs1), mobs2=mean(obs2), mobs3=mean(obs3))
Which gets me the right form, but how can I go about the summarize()
without typing mobsN=mean(obsN)
hundreds of times? I feel like an apply function will go in here but I'm not sure which...