Re: [R] how to speed up the inefficient code

2012-03-16 Thread jim holtman
Try this -- use matrices instead of dataframes if you want speed: > 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(r

Re: [R] how to speed up the inefficient code

2012-03-16 Thread Jorge I Velez
Hi mrzung46, Try cbind(p, result_1 = rowSums((p-c(test))^2)) HTH, Jorge.- On Fri, Mar 16, 2012 at 8:32 AM, mrzung <> wrote: > 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, > > >

[R] how to speed up the inefficient code

2012-03-16 Thread mrzung
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=rnor