Skip to content
Prev 288567 / 398498 Next

how to speed up the process of R

Hi,

Compare this:

a<-list()
system.time(for(i in 1:100000){
a[[i]]<-i*1000
})

system.time(a2 <- as.vector(1000 * (1:100000), "list"))
all.equal(a, a2)

## > system.time(for(i in 1:100000){
## + a[[i]]<-i*1000
## + })
##    user  system elapsed
##   28.66    0.02   28.84
## > system.time(a2 <- as.vector(1000 * (1:100000), "list"))
##    user  system elapsed
##       0       0       0
## > all.equal(a, a2)
## [1] TRUE

Cheers,

Josh
On Thu, Mar 15, 2012 at 5:00 PM, mrzung <mrzung46 at gmail.com> wrote: