AK: Thanks, that was very helpful. It led me to think of  the function 
names(base) which provided the vector of names in the correct order. I 
then used the same matrix formatting and everything worked out exactly 
as planned.
Dick
On 9/28/2012 1:09 AM, arun kirshna [via R] wrote:
>
>
> HI,
> May be this helps you:
> set.seed(1)
>  mat1<-matrix(rnorm(60,5),nrow=5,ncol=12)
> colnames(mat1)<-paste0("Var",1:12)
> vec2<-format(c(1,cor(mat1[,1],mat1[,2:12])),digits=4)
> vec3<-colnames(mat1)
> arr2<-array(rbind(vec3,vec2),dim=c(2,3,4))
> res<-data.frame(do.call(rbind,lapply(1:dim(arr2)[3],function(i) 
> arr2[,,i])))
>  res
> #        X1       X2       X3
> #1     Var1     Var2     Var3
> #2  1.00000  0.27890 -0.61497
> #3     Var4     Var5     Var6
> #4  0.24916 -0.76155  0.30853
> #5     Var7     Var8     Var9
> #6 -0.46413  0.79287  0.05191
> #7    Var10    Var11    Var12
> #8 -0.06940 -0.53251  0.06766
>
> A.K.
>
>
> ----- Original Message -----
> From: rkulp <[hidden email] 
> </user/SendEmail.jtp?type=node&node=4644469&i=0>>
> To: [hidden email] </user/SendEmail.jtp?type=node&node=4644469&i=1>
> Cc:
> Sent: Thursday, September 27, 2012 6:26 PM
> Subject: [R] List of Variables in Original Order
>
> 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.
>
> ______________________________________________
> [hidden email] </user/SendEmail.jtp?type=node&node=4644469&i=2> 
> 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.
>
>
> ______________________________________________
> [hidden email] </user/SendEmail.jtp?type=node&node=4644469&i=3> 
> 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.
>
>
> ------------------------------------------------------------------------
> If you reply to this email, your message will be added to the 
> discussion below:
> http://r.789695.n4.nabble.com/List-of-Variables-in-Original-Order-tp4644436p4644469.html
>  
>
> To unsubscribe from List of Variables in Original Order, click here 
> <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4644436&code=cmt1bHBAY2hhcnRlci5uZXR8NDY0NDQzNnwxOTU3MDkxNDkw>.
> NAML 
> <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>  
>



rkulp.vcf (418 bytes) 
<http://r.789695.n4.nabble.com/attachment/4644516/0/rkulp.vcf>




--
View this message in context: 
http://r.789695.n4.nabble.com/List-of-Variables-in-Original-Order-tp4644436p4644516.html
Sent from the R help mailing list archive at Nabble.com.
        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to