[R] how to speed up the inefficient code
mrzung
mrzung46 at gmail.com
Fri Mar 16 13:32:42 CET 2012
hi,
i'm really in trouble to simulate some experiment.
that is, it takes too much time to process the following code.
following is short example,
-------------------------------------------------------------------------------------------------------
p<-data.frame(a=rnorm(10),b=rnorm(10),c=rnorm(10),d=rnorm(10))
test<-data.frame(a=rnorm(1),b=rnorm(1),c=rnorm(1),d=rnorm(1))
result<-list()
for(i in 1:nrow(p)){
result[[i]]<-sum((p[i,]-test)^2)
}
result_1<-unlist(result)
p_1<-cbind(p,result_1)
-------------------------------------------------------------------------------------------------------
is there any efficient way to shorten the time and make same output?
--
View this message in context: http://r.789695.n4.nabble.com/how-to-speed-up-the-inefficient-code-tp4478046p4478046.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list