Hello, I have a 3 x 7 matrix. I want to assign a name to each row and each column. I tried using dimnames, but for some reason I cannot retrieve the names of the rows or the names of the columns. Is there another way to name the rows and columns and refer to them? [[alternative HTML version deleted]]
?rownames ?colnames> x <- matrix(nrow=7, ncol=3) > rownames(x) <- paste('name', 1:7) > rownames(x)[1] "name 1" "name 2" "name 3" "name 4" "name 5" "name 6" "name 7">On Sun, Dec 28, 2008 at 12:43 PM, Math Girl <mathmathgurl at yahoo.com> wrote:> Hello, > > I have a 3 x 7 matrix. I want to assign a name to each row > and each column. I tried using > dimnames, but for some reason I cannot retrieve the names of the rows or the names > of the columns. Is there another way to name the rows and columns and refer to them? > > > > [[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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Please read the last line to every message to r-help. There is no code in your post so we have no idea what you did wrong.> x <- matrix(1:12, 3, 4, dimnames = list(letters[1:3], LETTERS[1:4])) > xA B C D a 1 4 7 10 b 2 5 8 11 c 3 6 9 12> rownames(x)[1] "a" "b" "c"> colnames(x)[1] "A" "B" "C" "D"> dimnames(x)[[1]] [1] "a" "b" "c" [[2]] [1] "A" "B" "C" "D" On Sun, Dec 28, 2008 at 12:43 PM, Math Girl <mathmathgurl at yahoo.com> wrote:> Hello, > > I have a 3 x 7 matrix. I want to assign a name to each row > and each column. I tried using > dimnames, but for some reason I cannot retrieve the names of the rows or the names > of the columns. Is there another way to name the rows and columns and refer to them? > > > > [[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. >