aRrgh
aRrgh copied to clipboard
discuss dimension dropping
m <- matrix(1:9, nrow=3)
class( m[1:2, ] ) ## matrix!
class( m[1, ] ) ## integer!
Useful when you're expecting it, the cause of difficult to trace bugs when you're not. The terribly wonderful syntax
m[1, , drop=FALSE]
allows you to avoid dimension dropping explicitly.
Similarily, why apply
is evil (always drops dimensions if the function applied returns a scalar*)
*vector of length one