Re: [R] R annoyances

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Fri 20 May 2005 - 01:46:59 EST

Rod Montgomery wrote:

> 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?

First question: No.
Second question: No, because *many* functions do rely on the fact that x[,1] returns a vector rather than a matrix.

Uwe Ligges

> ______________________________________________
> 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



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:51:18 2005

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