[R] data frames; matching/merging
S Ellison
S.Ellison at lgc.co.uk
Mon Feb 8 17:59:16 CET 2010
You could try aggregate:
If we call your data frame df:
aggregate(df[2], by=df[1], FUN=min)
will get you what you asked for (if not necessarily what you need ;-)
)
Switching the columns around is easy enough if you need to; proceeding
stepwise:
df.new<-aggregate(df[2], by=df[1], FUN=min)
df.new[,c(2,1)]
As to how I found aggregate: watching R-help daily for years
occasionally pops up fundamental gems like aggregate...
Steve Ellison
LGC
>>> Jonathan <jonsleepy at gmail.com> 08/02/2010 16:39:11 >>>
What I'd like is to return a dataframe cut down to have only unique
entires in V1. V2 should contain a vector, for each V1, that is the
minimum of all the possible choices from the set of redundant V1's.
Example output:
V1 V2
1 a 2
2 b 9
3 c 4
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
More information about the R-help
mailing list