Germán Bonilla
2009-Jun-30 23:08 UTC
[R] difference between "names", "colnames" and "dimnames"
Hi all... I built a matrix binding vectors with rbind, and have something like this: [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] CLS 3.877328 4.087636 4.72089 4.038361 3.402942 2.786285 2.671222 3.276419 ORD NaN NaN NaN NaN 5.770780 5.901113 11.888054 7.934823 FAM NaN NaN NaN NaN NaN 3.699455 4.551196 2.885390 GEN NaN NaN NaN NaN NaN 3.967411 4.390296 2.885390 SPP NaN NaN NaN NaN NaN NaN NaN 2.885390 Then I tried to assign names to each column with names(), but end up with the following:> names(tester) <-c("uno","dos","tres","cuatro","cinco","seis","siete","ocho") [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] CLS 3.877328 4.087636 4.72089 4.038361 3.402942 2.786285 2.671222 3.276419 ORD NaN NaN NaN NaN 5.770780 5.901113 11.888054 7.934823 FAM NaN NaN NaN NaN NaN 3.699455 4.551196 2.885390 GEN NaN NaN NaN NaN NaN 3.967411 4.390296 2.885390 SPP NaN NaN NaN NaN NaN NaN NaN 2.885390 attr(,"names") [1] "uno" "dos" "tres" "cuatro" "cinco" "seis" "siete" "ocho" [9] NA NA NA NA NA NA NA NA [17] NA NA NA NA NA NA NA NA [25] NA NA NA NA NA NA NA NA [33] NA NA NA NA NA NA NA NA I can use colnames(tester), but then I cannot identify the colnames on the points when I plot them. How can I set the names(tester) for the whole matrix? Thanks a lot. Germán, UNAM [[alternative HTML version deleted]]
jim holtman
2009-Jul-01 03:10 UTC
[R] difference between "names", "colnames" and "dimnames"
You should be doing colnames(tester) <- c("uno","dos","tres","cuatro","cinco","seis","siete","ocho") On Tue, Jun 30, 2009 at 7:08 PM, Germán Bonilla <germanbr@gmail.com> wrote:> Hi all... > > I built a matrix binding vectors with rbind, and have something like this: > > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] > CLS 3.877328 4.087636 4.72089 4.038361 3.402942 2.786285 2.671222 3.276419 > ORD NaN NaN NaN NaN 5.770780 5.901113 11.888054 7.934823 > FAM NaN NaN NaN NaN NaN 3.699455 4.551196 2.885390 > GEN NaN NaN NaN NaN NaN 3.967411 4.390296 2.885390 > SPP NaN NaN NaN NaN NaN NaN NaN 2.885390 > > Then I tried to assign names to each column with names(), but end up with > the following: > > > names(tester) <- > c("uno","dos","tres","cuatro","cinco","seis","siete","ocho") > > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] > CLS 3.877328 4.087636 4.72089 4.038361 3.402942 2.786285 2.671222 3.276419 > ORD NaN NaN NaN NaN 5.770780 5.901113 11.888054 7.934823 > FAM NaN NaN NaN NaN NaN 3.699455 4.551196 2.885390 > GEN NaN NaN NaN NaN NaN 3.967411 4.390296 2.885390 > SPP NaN NaN NaN NaN NaN NaN NaN 2.885390 > attr(,"names") > [1] "uno" "dos" "tres" "cuatro" "cinco" "seis" "siete" "ocho" > [9] NA NA NA NA NA NA NA NA > [17] NA NA NA NA NA NA NA NA > [25] NA NA NA NA NA NA NA NA > [33] NA NA NA NA NA NA NA NA > > I can use colnames(tester), but then I cannot identify the colnames on the > points when I plot them. > > How can I set the names(tester) for the whole matrix? > > Thanks a lot. > > Germán, > UNAM > > [[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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]]
Don MacQueen
2009-Jul-01 13:47 UTC
[R] difference between "names", "colnames" and "dimnames"
I think your problem is with plotting, not with naming. Tell the list what kind of plot you're doing (with example code, of course) and where you need to see names on the plot. (What do you have in mind when you say names for the "whole" matrix? There are row names, and column names, and that's about it.) -Don At 6:08 PM -0500 6/30/09, Germ?n Bonilla wrote:>Content-Type: text/plain >Content-Disposition: inline >Content-length: 1771 > >Hi all... > >I built a matrix binding vectors with rbind, and have something like this: > > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] >CLS 3.877328 4.087636 4.72089 4.038361 3.402942 2.786285 2.671222 3.276419 >ORD NaN NaN NaN NaN 5.770780 5.901113 11.888054 7.934823 >FAM NaN NaN NaN NaN NaN 3.699455 4.551196 2.885390 >GEN NaN NaN NaN NaN NaN 3.967411 4.390296 2.885390 >SPP NaN NaN NaN NaN NaN NaN NaN 2.885390 > >Then I tried to assign names to each column with names(), but end up with >the following: > >> names(tester) <- >c("uno","dos","tres","cuatro","cinco","seis","siete","ocho") > > [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] >CLS 3.877328 4.087636 4.72089 4.038361 3.402942 2.786285 2.671222 3.276419 >ORD NaN NaN NaN NaN 5.770780 5.901113 11.888054 7.934823 >FAM NaN NaN NaN NaN NaN 3.699455 4.551196 2.885390 >GEN NaN NaN NaN NaN NaN 3.967411 4.390296 2.885390 >SPP NaN NaN NaN NaN NaN NaN NaN 2.885390 >attr(,"names") > [1] "uno" "dos" "tres" "cuatro" "cinco" "seis" "siete" "ocho" > [9] NA NA NA NA NA NA NA NA >[17] NA NA NA NA NA NA NA NA >[25] NA NA NA NA NA NA NA NA >[33] NA NA NA NA NA NA NA NA > >I can use colnames(tester), but then I cannot identify the colnames on the >points when I plot them. > >How can I set the names(tester) for the whole matrix? > >Thanks a lot. > >Germ?n, >UNAM > > [[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.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062