Possible Duplicate:
R Grouping functions: sapply vs. lapply vs. apply. vs. tapply vs. by vs. aggregate vs.
I'm using R and would love some help with a problem I'm having:
I have a dataframe (df
) with a column ID and a column Emotion. Each value in ID corresponds with 40-300 values in Emotion (so it's not a set number). I need to calculate the mean of all i's in Emotion
for each j in ID
. So this is what the data looks like
df$ID = (1, 1, 1, 1, 2, 2, 3)
df$Emotion = (2, 4, 6, 4, 1, 1, 8)
so the vector of means should look like this: (4, 1, 8)
Any help would be greatly appreciated!