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

2009-06-25 Thread Rama Ramakrishnan
Thanks, Gabor. Works great! On Thu, Jun 25, 2009 at 10:38 AM, Gabor Grothendieck < ggrothendi...@gmail.com> wrote: > Try this (shown for stated problem but generalizes by just adding > additional arguments): > > mapply("[", list(x), ltrs, mnths) > > > On Thu, Jun 25, 2009 at 10:24 AM, Rama Ramak

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? >> > > The apply method I just pos

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

2009-06-25 Thread Gabor Grothendieck
Try this (shown for stated problem but generalizes by just adding additional arguments): mapply("[", list(x), ltrs, mnths) On 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? > >

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

2009-06-25 Thread David Winsemius
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 method I just posted generalizes to higher dimensional arrays. -- DW On Thu, Jun 25, 2009 at 10:17 AM, Rama Ramakr

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

2009-06-25 Thread David Winsemius
On Jun 25, 2009, at 10:02 AM, Rama Ramakrishnan wrote: Dear R-Users, I need to lookup values from a 2-d table using the row names and column names as indices. I was wondering if there's a way to do this without an explicit loop. Example: #x is the 2-d table that holds the values x <- mat

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:11 AM, Henrique D

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

2009-06-25 Thread Henrique Dallazuanna
Try this: y$values <- diag(x[y$ltrs, y$mnths]) On Thu, Jun 25, 2009 at 11:02 AM, Rama Ramakrishnan wrote: > Dear R-Users, > I need to lookup values from a 2-d table using the row names and column > names as indices. I was wondering if there's a way to do this without an > explicit loop. > > Exam

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-Users, >> I need to lookup valu

[R] Efficient lookup on a two-dimensional table

2009-06-25 Thread Rama Ramakrishnan
Dear R-Users, I need to lookup values from a 2-d table using the row names and column names as indices. I was wondering if there's a way to do this without an explicit loop. Example: #x is the 2-d table that holds the values x <- matrix(rnorm(26*12),nrow=26) rownames(x) <- letters colnames(x) <