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

you need the correct number of commas.

For your example

> dim(out[1, drop=FALSE])
[1] 1
> out <- array(0, 5, list(1:5))
> dim(out)
[1] 5
> dim(out[1])
NULL
> dim(out[1, drop=FALSE])
[1] 1
>

This construct usually isn't needed for assignment

> out[2] <- 12
> out
 1  2  3  4  5
 0 12  0  0  0
> dim(out)
[1] 5
> dim(out[2])
NULL
> dim(out[2, drop=FALSE])
[1] 1
>


2012/1/31 Ernest Adrogué <nfdisco@gmail.com>

> Hi there,
>
> This is a problem I've run into and do not know how to avoid. It
> happens when I make an assignment using the dimension names as the
> subscript of the array. The end result is a dimenensionless array
> (i.e. a vector) which I don't want. See:
>
> > out <- array(0, 5, list(1:5))
> > dim(out)
> [1] 5
> > out[names(out)] <- 1
> > dim(out)
> NULL
>
> I tried to include a 'drop' argument into the index but it doesn't
> seem to work:
>
> > out[names(out), drop=FALSE] <- 1
> Error in out[names(out), drop = FALSE] <- 1 :
>  incorrect number of subscripts on matrix
>
> A solution would be to change the vector into an array myself, but I
> would like to hear opinions before I do that, because I would rather
> just make the assignment and keep the array object unchanged if such
> thing is possible. Also, using a subscript of integers instead of
> labels is not an option in this case.
>
> Any help appreciated.
>
> --
> Cheers,
> Ernest
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]

