[R] Confusing concept of vector and matrix in R

lith minilith at gmail.com
Tue Mar 30 22:08:20 CEST 2010

> Reframe the problem. Rethink why you need to keep dimensions. I never ever had to use drop.

The problem is that the type of the return value changes if you happen
to forget to use drop = FALSE, which can easily turn into a nightmare:

m <- matrix(1:20, ncol=4)
for (i in seq(3, 1, -1)) {
    print(class(m[1:i, ]))
[1] "matrix"
[1] "matrix"
[1] "integer"

More information about the R-help mailing list