Displaying 3 results from an estimated 3 matches for "impooved".
Did you mean:
improoved
2017 Aug 07
0
Has For bucle be impooved in R
The lapply loop and the for loop have very similar speed characteristics. Differences seen are almost always due to how you use memory in the body of the loop. This fact is not new. You may be under the incorrect assumption that using lapply is somehow equivalent to "vectorization", which it is not.
--
Sent from my phone. Please excuse my brevity.
On August 7, 2017 7:29:58 AM PDT,
2017 Aug 07
3
Has For bucle be impooved in R
Hi!
I am doing a lapply and for comparaison and I get that for is faster than lapply.
What I have done:
n<-100000
set.seed(123)
x<-rnorm(n)
y<-x+rnorm(n)
rand.data<-data.frame(x,y)
k<-100
samples<-split(sample(1:n),rep(1:k,length=n))
res<-list()
t<-Sys.time()
for(i in 1:100){
modelo<-lm(y~x,rand.data[-samples[[i]]])
2017 Aug 07
1
Has For bucle be impooved in R
Dear Jesus,
The difference is marginal when each code chunk does the same things. Your
for loop does not yields the same output as the lapply. Here is the cleaned
version of your code.
n<-10000
set.seed(123)
x<-rnorm(n)
y<-x+rnorm(n)
rand.data<-data.frame(x,y)
k<-100
samples <- split(sample(n), rep(seq_len(k),length=n))
library(microbenchmark)
microbenchmark(
"for"