Appendix 01 Benchmarking R Performance

library("microbenchmark") set.seed(1) d <- data.frame(V1=rnorm(1e6), V2=rnorm(1e6)) cbindSeqLen <- function(x) { return(cbind(id=seq_len(nrow(x)), x)) } dickoa <- function(x) { x$id <- seq_len(nrow(x)) return(x) } dickoaReorder <- function(x) { x$id <- seq_len(nrow(x)) nc <- ncol(x) x <- x[, c(nc, 1:(nc-1))] return(x) } microbenchmark(cbindSeqLen(d), dickoa(d), dickoaReorder(d), times=100)

Output

# Unit: milliseconds #             expr      min       lq   median       uq      max neval #   cbindSeqLen(d) 23.00683 38.54196 40.24093 42.60020 47.73816   100 #        dickoa(d) 10.70718 36.12495 37.58526 40.22163 72.92796   100 # dickoaReorder(d) 19.25399 68.46162 72.45006 76.51468 88.99620   100