[R] how can I give same name to column and row?
David L Carlson
dcarlson at tamu.edu
Thu Sep 20 05:14:00 CEST 2012
It does that automatically. Just assign the names you want to the data.frame
before you compute the correlation matrix:
> x <- data.frame(matrix(rnorm(100), ncol=5))
> colnames(x) <- c("A", "B", "C", "D", "E")
> y <- cor(x)
> y
A B C D E
A 1.00000000 -0.08053608 -0.05444754 0.02173336 -0.31879440
B -0.08053608 1.00000000 -0.02621494 0.16279797 -0.19011677
C -0.05444754 -0.02621494 1.00000000 -0.18518459 0.37355793
D 0.02173336 0.16279797 -0.18518459 1.00000000 -0.05316086
E -0.31879440 -0.19011677 0.37355793 -0.05316086 1.00000000
> rownames(y)
[1] "A" "B" "C" "D" "E"
> y <- cor(x)
> colnames(y)
[1] "A" "B" "C" "D" "E"
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Kristi Glover
> Sent: Wednesday, September 19, 2012 9:48 PM
> To: R-help
> Subject: [R] how can I give same name to column and row?
>
>
> Hi R User,
> I calculated a correlation matrix and I was trying to give a same name
> for rows and columns (heading) in the correlation matrix. But, I was
> not able to do so.
> Would you mind let me know how I can assign the same name for the
> heading of row and columns in the matrix?
>
> I appreciate for your help.
>
> cheers,
>
> K
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
More information about the R-help
mailing list