[R] Unique Pairs based on a Minimum Value
Bret Collier
bacollier at ag.tamu.edu
Tue Nov 6 01:33:55 CET 2007
RUsers,
I am trying (with little success) to determine how to combine unique and
min to do some data frame manipulations and I could use a little advice.
I have tried various combinations of 'unique', 'min' and 'apply' with
no luck.
Given this simple example data (x, y)
x<-c(10, 10, 12, 13, 15, 16 ,17, 17, 17)
y<-c(112, 117, 111, 117, 114, 113, 119, 121, 130)
as.data.frame(cbind(x, y))
x y
1 10 112
2 10 117
3 12 111
4 13 117
5 15 114
6 16 113
7 17 119
8 17 121
9 17 130
I have been attempting to get all those unique 'x-y' combinations for
which the y column is the minimum of the values y takes for each unique
x (ID variable), such as below.
x y
1 10 112
3 12 111
4 13 117
5 15 114
6 16 113
7 17 119
Any advice/directions I could look would be appreciated.
TIA,
Bret
R 2.6.0; platform i386-pc-mingw32
More information about the R-help
mailing list