Possible Duplicate:
R: compute correlation by groupR: compute correlation by group
I have a data set with a 6 or so data points for groups of data.
e.g.:
email_id date_sent number_sent number_of_views number_of_responses
1 5/4 600 25 6
1 5/5 500 22 8
1 5/6 450 23 4
1 5/7 700 34 12
2 5/5 900 30 10
2 5/6 750 28 11
...
(this is made up data that illustrates the point)
Assuming I have this in a data frame in R, I'd like to write something which will give me stats by group. I'm most interested in the correlation coefficient between some of the columns.
I know how to do this with a data frame that contains only one group:
cor(col1, col2)
but I'd like to learn a technique that will allow me to extract data that looks something like this:
email_id cor(col3, col4)
1 .73
2 .85
3 .98
and so on.
Thanks,