Skip to content
Prev 74716 / 398502 Next

converting stata's by syntax to R

Here is one way this can be done
 do.call("rbind", by(dat, list(dat$fam) ,function(x) {
+ if(NROW(x)>1) return(x[which.max(x$wt),])
+ else return(x)}
+ ))


and it returns
  fam  wt keep
1   1 1.0    1
2   2 1.0    1
3   3 0.6    1
4   4 0.4    1



hth,
On Mon, 1 Aug 2005, Chris Wallace wrote: