[R] cannot assign dimnames

Liaw, Andy andy_liaw at merck.com
Mon Sep 27 16:54:34 CEST 2004


I believe the posting guide ask you to show an example of what you tried,
just so people have a better idea of where you went off track.

I thought ?dimnames is rather explicit on this:

[...]
Usage:

     dimnames(x)
     dimnames(x) <- value

Arguments:

       x: an R object, for example a matrix, array or data frame.

   value: a possible value for 'dimnames(x)': see "Value".

[...]

Value:

     The dimnames of a matrix or array can be 'NULL' or a list of the
     same length as 'dim(x)'.  If a list, its components are either
     'NULL' or a character vector the length of the appropriate
     dimension of 'x'.

Thus, something like:

> x <- matrix(1:12, 3, 4)
> x
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12
> dimnames(x) <- list(letters[1:nrow(x)], LETTERS[1:ncol(x)])
> x
  A B C  D
a 1 4 7 10
b 2 5 8 11
c 3 6 9 12

Andy

> From: Dan Bebber
> 
> Dear list,
> 
> If anyone knows how to assign dimnames to matrices or arrays 
> I would be most
> grateful for help. I've tried various permutations of 
> likely-looking code
> but get error messages every time. I could find no example in the
> documentation.
> 
> Many thanks,
> Dan Bebber
> 
> Department of Plant Sciences
> University of Oxford
> South Parks Road
> Oxford OX1 3RB
> UK
> Tel. 01865 275000
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list