Aluma Dembo
  • Home
  • Research
  • About
  • Home
  • Research
  • About

The R Inferno

9/17/2016

 
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.
The R Inferno
 Among the many new things I learned and immediately implemented: 
  • the amazing "drop = FALSE" argument that prevents subscripted matrices from dropping a dimension and becoming vectors
As Burns so helpfully repeats twice on page 67:
"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.

    Author

    Just an aggregation of things I like.

    Categories

    All
    Experiments
    R
    Tips

aluma.dembo [at] idc[dot] ac<dot>il
Copyright © 2021