[R] ugly loop

2005-04-22 Thread Bill Simpson
The following code is slow and ugly: count-0 for(i in 1:nrow(ver)) for(j in 1:ncol(ver)) { count-count+1 x[count]-pt$x[ver[i,j]] y[count]-pt$y[ver[i,j]] z[count]-pt$z[ver[i,j]] } Please help me make it better. Thanks! Bill

Re: [R] ugly loop

2005-04-22 Thread Dimitris Rizopoulos
/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm - Original Message - From: Bill Simpson [EMAIL PROTECTED] To: r-help r-help@stat.math.ethz.ch Sent: Friday, April 22, 2005 2:58 PM Subject: [R] ugly loop The following code is slow and ugly: count-0 for(i in 1:nrow(ver

Re: [R] ugly loop

2005-04-22 Thread Marc Schwartz
On Fri, 2005-04-22 at 08:58 -0400, Bill Simpson wrote: The following code is slow and ugly: count-0 for(i in 1:nrow(ver)) for(j in 1:ncol(ver)) { count-count+1 x[count]-pt$x[ver[i,j]] y[count]-pt$y[ver[i,j]] z[count]-pt$z[ver[i,j]] } Please help me make it

Re: [R] ugly loop

2005-04-22 Thread Bill Simpson
To clarify: I want to get rid of the loop over i,j Here is a simpler example. ver is a 2D matrix count-0 for(i in 1:nrow(ver)) for(j in 1:ncol(ver)) { count-count+1 x[count]-ver[i,j] } Bill __ R-help@stat.math.ethz.ch mailing list

Re: [R] ugly loop

2005-04-22 Thread Dimitris Rizopoulos
://www.student.kuleuven.ac.be/~m0390867/dimitris.htm - Original Message - From: Bill Simpson [EMAIL PROTECTED] To: r-help r-help@stat.math.ethz.ch Sent: Friday, April 22, 2005 3:17 PM Subject: Re: [R] ugly loop To clarify: I want to get rid of the loop over i,j Here is a simpler example. ver is a 2D

Re: [R] ugly loop

2005-04-22 Thread Bill Simpson
Thanks Marc for your help. The following code is slow and ugly: count-0 for(i in 1:nrow(ver)) for(j in 1:ncol(ver)) { count-count+1 x[count]-pt$x[ver[i,j]] y[count]-pt$y[ver[i,j]] z[count]-pt$z[ver[i,j]] } Please help me make it better.

Re: [R] ugly loop

2005-04-22 Thread Woodrow Setzer
] ugly loop On Fri, 2005-04-22 at 08:58 -0400, Bill Simpson wrote: The following code is slow and ugly: count-0 for(i in 1:nrow(ver)) for(j in 1:ncol(ver)) { count-count+1 x[count]-pt$x[ver[i,j]] y[count]-pt$y[ver[i,j]] z[count]-pt$z[ver[i,j]] } Please help me

Re: [R] ugly loop

2005-04-22 Thread Marc Schwartz
On Fri, 2005-04-22 at 09:31 -0400, Bill Simpson wrote: Thanks Marc for your help. The following code is slow and ugly: count-0 for(i in 1:nrow(ver)) for(j in 1:ncol(ver)) { count-count+1 x[count]-pt$x[ver[i,j]] y[count]-pt$y[ver[i,j]]

Re: [R] ugly loop

2005-04-22 Thread Bill Simpson
On Fri, 22 Apr 2005, Marc Schwartz wrote: Thus, I just need to use t(ver) instead of ver: x - pt$x[t(ver)] y - pt$y[t(ver)] z - pt$z[t(ver)] That should do it? Yep!! Thanks very much Marc and others who suggested this. Cheers Bill __