[R] sapply and loop
Liaw, Andy
andy_liaw at merck.com
Sat Oct 16 14:23:54 CEST 2004
Without seeing what myfunction is, it's almost impossible to tell.
In addition to system.time(), you might want to profile your code. e.g.,
Rprof()
zz <- sapply(ma, myfunction)
Rprof(NULL)
summaryRprof()
HTH,
Andy
> From: Zhen Pang
>
> Dear all,
>
> I am doing 200 times simulation. For each time, I generate a
> matrix and
> define some function on this matrix to get a 6 dimension vector as my
> results.
>
> As the loop should be slow, I generate 200 matrice first, and
> save them into
> a list named ma,
> then I define zz<-sapply(ma, myfunction)
>
> To my surprise, It almost costs me the same time to get my
> results if I
> directly use a loop from 1 to 200. Is it common? Can I
> improve any further?
>
> Ps, how to count the exact time to finish my code?
>
> Thanks.
>
> Zhen
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
More information about the R-help
mailing list