Hello:

I am working on trying to subset a data.frame using a vector of headings as a single 'key'. I have things to the point where I can get the unique sets of keys but I'm stuck on how to use these in a subset call.

So far, I've got something similar to:


   cols <- c('V1','V2')
   keys <- unique (subset (df, select = cols))

This gives me something like:

   > keys
     V1 V2
   1  1  2
   2  1  3
   3  2  1
   4  4  1

What I'd like is to be able, for each row of keys, to do something similar to:

   subset (df, c('V1',V2') == keys[1,])

Which is obviously invalid.

Any suggestions on what is the best way to get the subset from this aggregate key? This example has only two columns selected but I need to support a variable number of columns used as the 'key'

Thanks,

Jesse

______________________________________________
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
and provide commented, minimal, self-contained, reproducible code.

Reply via email to