I apologize for not being specific enough in my previous posting. Assume
you have panel data in the form:
df <- data.frame( cbind( rep( c( "AUT" , "BEL" , "DEN" , "GER" ) , 4) ,
cbind( rep( c( 1999 , 2000 , 2001 , 2002 ) , 4 ) ), sample( 10 , 16 ,
replace=T) ) )
names(df) <- c( "country" , "year" , "x" )
1. I would like to compute the correlation matrix between countries
based on the annual observations of the variable x. I tried the following:
library( combinat )
temp <- split( df$x, df$year )
apply( combn(4,2) , 2 , function(x) cor( temp[[1]] , temp[[2]] ) )
This gives wrong answer. Why?
2. The pairwise correlations computed as above should be in the order:
GER with BEL, GER with DEN, GER with AUT, BEL with DEN, BEL with AUT,
DEN with AUT.
That is, the correctly sorted vector of factors is:
SORT <- c( "GER" , "BEL" , "DEN" , "AUT" ) not c( "AUT" , "BEL" , "DEN"
, "GER" )
May be there is an altogether better way of achieving what I want?
Serge
______________________________________________
R-help@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.