Re: [R] R annoyances

From: Rod Montgomery <monty_at_sprintmail.com>
Date: Fri 20 May 2005 - 01:35:38 EST

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?


R-help@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 Received on Fri May 20 01:45:15 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:55 EST