Skip to content
Prev 309851 / 398506 Next

select duplicate identifier with higher mean across sample columns

Hello,

Thanks for the data example. (You forgot samp2a).
Try the following.


mdf <- read.table(text="
id samp1 samp2 samp2a
1  A   100   110    110
2  A   120   130    150
3  C   101   131    151
4  D   110   150    130
5  E   132   122    122
6  F   123   143    143
", header=TRUE)

idx <- ave(rowMeans(mdf[,-1]), mdf$id, FUN = function(x) x == max(x))
mdf[as.logical(idx), ]


Hope this helps,

Rui Barradas
Em 04-11-2012 19:25, Adrian Johnson escreveu: