[R] Correlation matrix for data in long format

Henrique Dallazuanna wwwhsd at gmail.com
Tue Jan 29 14:46:34 CET 2008


If I understand your question, you can try something like this:

cor(data.frame(lapply(split(x, x$state), "[", 3)))

On 29/01/2008, Serguei Kaniovski <Serguei.Kaniovski at wifo.ac.at> wrote:
> Hello,
>
> I cannot figure out how to use "tapply" to compute the correlation matrix
> in the variable "x" between the states? The data is in long format, e.g.:
>
> state,year,x
> Alabama,2001,0.45
> Alabama,2002,0.47
> Alabama,2003,0.48
> Alabama,2004,0.44
> Arizona,2001,0.34
> Arizona,2002,0.32
> Arizona,2003,0.38
> Arizona,2004,0.36
>
> Thank you in advance for your help,
> Serguei Kaniovski
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list