[R] Re: cannot assign dimnames
Gabor Grothendieck
ggrothendieck at myway.com
Mon Sep 27 22:01:42 CEST 2004
Gabor Grothendieck <ggrothendieck <at> myway.com> writes:
:
: Dan Bebber <danbebber <at> forestecology.co.uk> writes:
:
: : Please ignore my earlier message on this topic. I was under the mistaken
: : impression that dimnames() named the dimensions themselves, rather than the
: : indices within the dimensions.
:
: What you are referring to is done in R by referring to the names of
: the dimnames, as opposed to the dimnames, themselves. Here is an
: example:
:
: R> mat <- matrix(1:12,4, dimnames = list(letters[1:4],LETTERS[1:3]))
: R> names(dimnames(mat)) <- c("FirstDim", "SecondDim")
: R> mat
: SecondDim
: FirstDim A B C
: a 1 5 9
: b 2 6 10
: c 3 7 11
: d 4 8 12
Perhaps I should have also mentioned that the above could be done
in a single line like this:
R> mat <- matrix(1:12,4, dimnames = list(FirstDim = letters[1:4], SecondDim =
LETTERS[1:3]))
R> mat
SecondDim
FirstDim A B C
a 1 5 9
b 2 6 10
c 3 7 11
d 4 8 12
More information about the R-help
mailing list