[R] Correlations by subgroups

2011-06-15 Thread jfdawson
I'm hoping there is a simple answer to this - it seems that there should be, but I can't figure it out. I have a matrix/data frame with three variables of interest - V1, V2, V3. One, V1, is a factor with x levels (x may be a large number); I want to calculate the correlation between the other

Re: [R] Correlations by subgroups

2011-06-15 Thread jfdawson
ddply(dat, .(V1), summarize, cor.v2.v3 = cor(V2, V3)) Best, Ista On Wed, Jun 15, 2011 at 10:31 AM, jfdawson [hidden email]x-msg://177/user/SendEmail.jtp?type=nodenode=3600456i=0 wrote: I'm hoping there is a simple answer to this - it seems that there should be, but I can't figure it out. I

Re: [R] Correlations by subgroups

2011-06-15 Thread jfdawson
Many thanks - this is very helpful indeed! Best wishes, Jeremy On 15 Jun 2011, at 21:58, Daniel Malter [via R] wrote: x-c(1,1,1,1,1,2,2,2,2,2) y-rnorm(10) z-y+rnorm(10) by(data.frame(y,z),factor(x),cor) hth, Daniel jfdawson wrote: I'm hoping there is a simple answer to this - it seems