Whenever you take a 1 column slice of a matrix, that gets automatically converted into a vector. But if you take a slice of several columns, it remains a matrix. The problem is you don’t always know in advance how big the slice will be, so if you do this:
You'll get an error if x is 1. This creates the worst kind of bug: an intermittent one that will hide until the right (wrong?) value of x occurs. To fix the problem you need to RE-declare the slice to be a matrix with ncol=x after you take the slice.
See this discussion for some useful advice …
http://groups.google.com/group/r-help-archive/browse_thread/thread/978eb088ad2573ee/0908e687fcbe8322
HTH,
– S.
Hi Stu,
Thanks for the link. I didn’t know about the
drop=F
option.
Every programming language has it’s quirks and hidden bogies, but R seems to have more than its fair share, a situation made worse by the documentation (something I’ll write more about in a future post).
Cheers,
Matt