R annoyances 2005-05-19 - By Rod Montgomery
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@(protected) mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
|
|