Re: [R] Need a vectorized way to avoid two nested FOR loops

2009-10-08 Thread Rama Ramakrishnan
Bert, Jim, Dimitris and Joris, Thank you all very much for your prompt help and suggestions. After trying the ideas out, I have decided to go with Bert's approach since it is by far the fastest of the lot. Thanks again! Rama Ramakrishnan On Oct 8, 2009, at 12:49 PM, Bert Gunter

[R] Need a vectorized way to avoid two nested FOR loops

2009-10-07 Thread Rama Ramakrishnan
e a for loop stepping through each row in d, and within the loop have another loop going through all the rows again, checking for equality. This is quadratic in the number of rows and takes way too long. Is there a better, "vectorized" way to do this? Thanks in advance! Rama

Re: [R] Efficient lookup on a two-dimensional table

2009-06-25 Thread Rama Ramakrishnan
n Thu, Jun 25, 2009 at 10:24 AM, Rama Ramakrishnan > wrote: > > Follow-on question: is there a way to do this for higher-dimensional > (i.e. > > more than 2 dimensions) arrays? > > > > > > On Thu, Jun 25, 2009 at 10:17 AM, Rama Ramakrishnan >wrote: > > >

Re: [R] Efficient lookup on a two-dimensional table

2009-06-25 Thread Rama Ramakrishnan
Thanks, David, that works too! On Thu, Jun 25, 2009 at 10:30 AM, David Winsemius wrote: > > On Jun 25, 2009, at 10:24 AM, Rama Ramakrishnan wrote: > > Follow-on question: is there a way to do this for higher-dimensional (i.e. >> more than 2 dimensions) arrays? >> >

Re: [R] Efficient lookup on a two-dimensional table

2009-06-25 Thread Rama Ramakrishnan
Follow-on question: is there a way to do this for higher-dimensional (i.e. more than 2 dimensions) arrays? On Thu, Jun 25, 2009 at 10:17 AM, Rama Ramakrishnan wrote: > That works!! Very nice way to do it! Thank you, Henrique! > Rama Ramakrishnan > > > On Thu, Jun 25, 2009 at 10:

Re: [R] Efficient lookup on a two-dimensional table

2009-06-25 Thread Rama Ramakrishnan
That works!! Very nice way to do it! Thank you, Henrique! Rama Ramakrishnan On Thu, Jun 25, 2009 at 10:11 AM, Henrique Dallazuanna wrote: > Try this: > > y$values <- diag(x[y$ltrs, y$mnths]) > > On Thu, Jun 25, 2009 at 11:02 AM, Rama Ramakrishnan wrote: > >> Dear R

[R] Fwd: Efficient lookup on a two-dimensional table

2009-06-25 Thread Rama Ramakrishnan
re a more efficient way (e.g., one without using an explicit loop) to do this? Thanks in advance! -Rama Ramakrishnan [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEAS

[R] Efficient lookup on a two-dimensional table

2009-06-25 Thread Rama Ramakrishnan
s as keys to look up # the associated value from x #One way to do this is with a FOR loop for (i in 1:nrow(y)) {y$val[i] <- x[y$ltrs[i],y$mnths[i]]} My question: Is there a more efficient way (e.g., one without using an explicit loop) to do this? Thanks in advance! -R