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,
>
>
> -------------------------------------------------------------------------------------------------------
>
> 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.
>
> ______________________________________________
> 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.
>

	[[alternative HTML version deleted]]

