On 9/29/2011 5:24 PM, Joe Grzymski wrote:
> All
> I am plotting variables on the same plot using scaled common ranges.
>
> Given a data.frame from the R data sets: "mtcars" it is simple to scale any
> one variable
>
> range01<-function(x){
> rng<-range(x,na.rm=TRUE)
> (x-rng[1])/diff(rng)
> }
>
> mtcars<-mutate(mtcars,scaledhp=range01(hp))
>
> is there a trivial way to scale hp according to its cylinder (cyl)
> without individually scaling and then putting back together in a data.frame
> like this:
library("plyr")
new <- ddply(mtcars, .(cyl), mutate, scaledhp=range01(hp))
--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University