[R] Why does this work? plyr within-subset normalization

Justin Haynes jtor14 at gmail.com
Wed Mar 28 22:14:36 CEST 2012

To those without access to nabble, the code in reference is:

relative <- ddply(ranktable, .(Timestamp), function(x)
data.frame(relative = x[,5]/max(x[,5])))

I may be misunderstanding your question, but:

ddply splits your data.frame, ranktable, by the column Timestamp into
many smaller data.frames, one for each unique Timestamp value.

Those new small data.frames are sent one at a time to the function you
So, when you call max(x[,5]) you're taking the max of the data.frame
sent to the function rather than the max of the larger ranktable

On Wed, Mar 28, 2012 at 10:18 AM, z2.0 <zack.abrahamson at gmail.com> wrote:
> Working code that normalize each row's value against the subset's maximum.
> Does the invocation of max() somehow instruct R to 'step back' and evaluate
> the subset?
> Thanks, Zack
> --
> View this message in context: http://r.789695.n4.nabble.com/Why-does-this-work-plyr-within-subset-normalization-tp4512989p4512989.html
> Sent from the R help mailing list archive at Nabble.com.
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list