I recently came across The R Inferno written by Patrick Burns. In a satirical style following Dante's Inferno, he discusses pretty much every stack exchange question I've ever looked up.
Among the many new things I learned and immediately implemented:
"NOTE: Failing to use drop=FALSE inside functions is a major source of bugs. "
Suppose you have a matrix my.Matrix and you want to take some subset my.subset of the rows in M.
> M[ my.subset, ]
If my.subset has length 1, then the above code will return a single vector.
> M[ my.subset, , drop = FALSE]
Even if my.subset has length 1, the above will return a matrix with a single row.
aluma.dembo [at] economics [dot] ox[.]ac<dot>uk
Copyright © 2019