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 <mrzun...@gmail.com> wrote:
> hi
>  I'm simulating some experiment by "for" function.
> The problem is that it takes too much time.
>
> for example,
>
> a<-list()
>
> for(i in 1:100000000){
> a[[i]]<-i*1000
> }
>
> is there anyway to speed up the process?
> I heard there is solution but i don't have idea.
>
> Can anyone help me?
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/how-to-speed-up-the-process-of-R-tp4476794p4476794.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to