data.table - R double the size of a datatable -
data.table - R double the size of a datatable -
i have next datatable:
dt = data.table( v1=as.character(rnorm(5)), v2=as.character(rnorm(5)), v3=as.character(rnorm(5)), v4=as.character(rnorm(5)), v5=as.character(rnorm(5)) )
and want double size duplicating column.
i proceed this:
dt2 <- with(dt, data.table( v1=rep(v1,2), v2=rep(v2,2), v3=rep(v3,2), v4=rep(v4,2), v5=rep(v5,2) )
is there faster way iterate on colnames?
if it's speed you're after...
microbenchmark( rbindlist(list(dt, dt)), dt[rep(1:nrow(dt), 2), ], rbind(dt, dt) )
giving:
expr min lq median uq max neval rbindlist(list(dt, dt)) 121.516 126.8520 130.9580 136.9105 353.052 100 dt[rep(1:nrow(dt), 2), ] 784.102 814.0705 848.7600 957.3445 5709.986 100 rbind(dt, dt) 864.976 906.2335 958.5755 1085.6325 1961.897 100
r data.table
Comments
Post a Comment