> tmp2 <- matrix(1:8,4,2)
> dimnames(tmp2)
NULL
> tmp2
     [,1] [,2]
[1,]    1    5
[2,]    2    6
[3,]    3    7
[4,]    4    8
> dimnames(tmp2)[[2]] <- c("a","b")
> tmp2
     a b
[1,] 1 5
[2,] 2 6
[3,] 3 7
[4,] 4 8
> tmp1 <- matrix(1:4,4,1)
> dimnames(tmp1)
NULL
> tmp1
     [,1]
[1,]    1
[2,]    2
[3,]    3
[4,]    4
> dimnames(tmp1)[[2]] <- "a"
Error in dimnames(tmp1)[[2]] <- "a" : 'dimnames' must be a list
## this error caught me by surprise.  Since this is a replaement,I
think it should work parallel
## to the two column case.  My reading of the ?Extract description of drop
   drop: For matrices and arrays.  If ‘TRUE’ the result is coerced to
the lowest possible dimension (see
          the examples).  This only works for extracting elements, not
for the replacement.  See ‘drop’
          for further details.
suggests that this should work for the one column case.

Two alternate methods that do work are
> dimnames(tmp1) <- list(1:4,"a")
> colnames(tmp1) <- "a"

Rich

______________________________________________
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
and provide commented, minimal, self-contained, reproducible code.

Reply via email to