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
/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
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
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
://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
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.
] 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
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]]
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
__