[R] Normalizing grouped data in a data frame

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Fri Nov 9 19:20:30 CET 2007


Greg Snow wrote:
> Here is another approach using transform and ave which I think is a
> little simpler than the others suggested:
>
>   
>> new.data <- transform( iris, 
>>     
> +   normSW = Sepal.Width / ave(Sepal.Width, Species, FUN=max),
> +   normSL = Sepal.Length / ave(Sepal.Length, Species, FUN=max)
> +  )
>
> You can adjust it for your data.  Hope this helps,
>
>   
Yes, I was about to suggest the same. Or

...ave(Sepal.Width, Species, FUN = function(x) x/max(x))..

Should we have a competition for a more evocative name than "ave"?

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list