[R] subset with aggregate key
Jesse Brown
jesse.r.brown at lmco.com
Mon Jul 11 13:43:37 CEST 2011
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
More information about the R-help
mailing list