[R] The L Word

Hadley Wickham hadley at rice.edu
Thu Feb 24 17:14:35 CET 2011


> Note however that I've never seen evidence for a *practical*
> difference in simple cases, and also of such cases as part of a
> larger computation.
> But I'm happy to see one if anyone has an interesting example.
>
> E.g., I would typically never use  0L:100L  instead of 0:100
> in an R script because I think code readability (and self
> explainability) is of considerable importance too.

But : casts to integer anyway:

> str(0:100)
 int [1:101] 0 1 2 3 4 5 6 7 8 9 ...

And performance in this case is (obviously) negligible:

> library(microbenchmark)
> microbenchmark(as.integer(c(0, 100)), times = 1000)
Unit: nanoeconds
                      min  lq median  uq   max
as.integer(c(0, 100)) 712 791    813 896 15840

(mainly included as opportunity to try out microbenchmark)

So you save ~800 ns but typing two letters probably takes 0.2 s (100
wpm, ~ 5 letters per word + space = 0.1s per letter), so it only saves
you time if you're going to be calling it more than 125000 times ;)

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-help mailing list