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 wrote

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

2009-10-07 Thread Rama Ramakrishnan
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 Ramakrishnan

[R] Efficient lookup on a two-dimensional table

2009-06-25 Thread Rama Ramakrishnan
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! -Rama Ramakrishnan [[alternative HTML version deleted

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

2009-06-25 Thread Rama Ramakrishnan
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 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html

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 www...@gmail.comwrote: Try this: y$values - diag(x[y$ltrs, y$mnths]) On Thu, Jun 25, 2009 at 11:02 AM, Rama Ramakrishnan r...@alum.mit.eduwrote: Dear R-Users

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 r...@alum.mit.eduwrote: That works!! Very nice way to do it! Thank you, Henrique! Rama Ramakrishnan On Thu, Jun 25, 2009 at 10:11

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 dwinsem...@comcast.netwrote: 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? The apply

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

2009-06-25 Thread Rama Ramakrishnan
...@alum.mit.edu 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 r...@alum.mit.edu wrote: That works!! Very nice way to do it! Thank you, Henrique! Rama Ramakrishnan