R Tip: Use drop = FALSE with data.frames
Another R tip. Get in the habit of using drop = FALSE when indexing (using [ , ] on) data.frames. Prince Rupert’s drops (img: Wikimedia Commons)
Another R tip. Get in the habit of using drop = FALSE when indexing (using [ , ] on) data.frames. Prince Rupert’s drops (img: Wikimedia Commons)
Is R base::subset() really that bad?
R tip: force the use of named arguments when designing function signatures. R’s named function argument binding is a great aid in writing correct programs. It is a good idea, if practical, to force optional arguments to only be usable by name. To do this declare the additional arguments after […]
R tip: use [[ ]] wherever you can. In R the [[ ]] is the operator that (when supplied a simple scalar argument) pulls a single element out of lists (and the [ ] operator pulls out sub-lists). For vectors [[ ]] and [ ] appear to be synonyms (modulo […]
Another R tip. Use seq_len() to avoid the backwards sequence trap. Many R users use the “colon sequence” notation to build sequences. For example: for(i in 1:5) { print(paste(i, i*i)) } #> [1] "1 1" #> [1] "2 4" #> [1] "3 9" #> [1] "4 16" #> [1] "5 […]
Here is an R tip. Need to quote a lot of names at once? Use qc(). This is particularly useful in selecting columns from data.frames: library(“wrapr”) # get qc() definition head(mtcars[, qc(mpg, cyl, wt)]) # mpg cyl wt # Mazda RX4 21.0 6 2.620 # Mazda RX4 Wag 21.0 6 […]
I am going to write about an insidious statistical, data analysis, and presentation fallacy I call “the zero bug” and the habits you need to cultivate to avoid it. The zero bug Here is the zero bug in a nutshell: common data aggregation tools often can not “count to zero” […]