Skip to content
Back to formatted view

Raw Message

Message-ID: <43F0CFEF.3070900@inf.ed.ac.uk>
Date: 2006-02-13T18:29:03Z
From: Roger Levy
Subject: indexing via a character matrix?

Hi,

Is it possible to index via a character matrix?  For example, I would 
like to do the following:

cont.table <- table(df1$A,df1$B) # df1 a data frame with factors A and B
cont.table[cbind(df2$A,df2$B)]   # df2 a smaller data frame with some
                                  # pairings of values for A and B

but the second step does not work -- I guess that matrices to be used 
for indexing this way must be numeric.  Is there a way to index multiple 
character tuples out of a contingency table without resorting to writing 
loops?

Many thanks,

Roger Levy