[R] List of Variables in Original Order
rkulp
rkulp at charter.net
Fri Sep 28 00:26:36 CEST 2012
I am trying to Sweave the output of calculating correlations between one
variable and several others. I wanted to print a table where the
odd-numbered rows contain the variable names and the even-numbered rows
contain the correlations. So if VarA is correlated with all the variables in
mydata.df, then it would look like
var1 var2 var3
corr1 corr2 corr3
var4 var5 var6
corr4 corr5 corr6
.
.
etc.
I tried using a matrix for the correlations and another one for the variable
names. I built the correlation matrix using
x = matrix(format(cor(mydata.df[,1],mydata.df[,c(2:79)]),digits=4),nc=3)
and the variable names matrix using
y = matrix(ls(mydata.df[c(2:79)]),nc=3).
The problem is the function ls returns the names in alphabetical order,
columnar order.
How do I get the names in columnar order? Is there a better way to display
the correlation of a single variable with a large number of other variables?
If there is, how do I do it? I appreciate any help I can get. This is my
first project in R so I don't know much about it yet.
--
View this message in context: http://r.789695.n4.nabble.com/List-of-Variables-in-Original-Order-tp4644436.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list