[R] aggregation-type question
jrkrideau at inbox.com
Fri Feb 8 19:03:44 CET 2013
I seem to be suffering from the same problem (the Friday one, not the cor one)
Have a look at http://stats.stackexchange.com/questions/4040/r-compute-correlation-by-group for something that looks like it will work
Kingston ON Canada
> -----Original Message-----
> From: david.carslaw at kcl.ac.uk
> Sent: Fri, 8 Feb 2013 08:33:45 -0800 (PST)
> To: r-help at r-project.org
> Subject: [R] aggregation-type question
> I seem to have a Friday afternoon block and can't see the easiest way of
> doing this.
> Given a data frame like:
> dat <- data.frame(x = runif(100), y = runif(100), group =
> each = 10))
> x y group
> 1 0.876751503 0.6518345 a
> 2 0.627067150 0.8801790 a
> 3 0.632465192 0.1768305 a
> 4 0.060359554 0.8835652 a
> 5 0.675868776 0.7721177 a
> 6 0.008465241 0.5046486 a
> I want to work out cor(x, y) by group, so in this case ending up with 10
> correlation coefficients by group.
> I'm not seeing a straightforward solution and I'd appreciate your help.
> View this message in context:
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
More information about the R-help