[R] Merging by() results back into original data frame?

ivo welch ivowel at gmail.com
Mon Mar 21 23:42:43 CET 2011


dear R experts---I am trying to figure out what the recommended way is
to merge by() results back into the original data frame.  for example,
I want to have a flag that tells me whether a particular row contains
the maximum for its group.

  d <- data.frame(group=as.factor(rep(1:3,each=3)), val=rnorm(9))
  highestvals <- by( d, d$group, function(d)(max(d$val)) )

  ## and now?  iterate over levels( d$group ) ?  how do I merge
highestvals back into d?

advice appreciated.

sincerely,

/iaw
----
Ivo Welch (ivo.welch at brown.edu, ivo.welch at gmail.com)



More information about the R-help mailing list