Why does this work? plyr within-subset normalization

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Why does this work? plyr within-subset normalization

z2.0
Working code that normalize each row's value against the subset's maximum.

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

Does the invocation of max() somehow instruct R to 'step back' and evaluate the subset?

Thanks, Zack
Reply | Threaded
Open this post in threaded view
|

Re: Why does this work? plyr within-subset normalization

Justin Haynes
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
specify.
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
data.frame.




On Wed, Mar 28, 2012 at 10:18 AM, z2.0 <[hidden email]> 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.
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.