[R] R annoyances

Rod Montgomery monty at sprintmail.com
Thu May 19 17:35:38 CEST 2005

Thomas Lumley wrote:
> On Thu, 19 May 2005, Chalasani, Prasad wrote:
>> (b) When extracting 2 or more columns of a matrix,
>>    R returns the result as a matrix, BUT when extracting
>>    just one column, it returns a vector/array, rather than
>>    a matrix, so I've to keep doing as.matrix, which is annoying.
>>     sub.mtx <- as.matrix(mtx[,1])
>>     Of course I could write a suitable function
>>         cols <- function(mtx,range) as.matrix(mtx[, range])
>>     but then I lose the syntactic sugar of being able to say "[,1]".
> This one is actually a FAQ,
>         mtx[,1,drop=FALSE]
>     -thomas
I wonder whether there is, or should be, a way to set FALSE as the default?

More information about the R-help mailing list