[R] Scalling/Centering the Data by an Index

Simon Blomberg blomsp at ozemail.com.au
Thu Jul 13 08:54:31 CEST 2006


If you want to centre the data, but not scale as well, turn off scale:

unlist(tapply(x, group, scale, scale=FALSE))

HTH,

Simon.

Ashraf Chaudhary wrote:
> Dear All:
> I would like to center the data in 'x' by 'group'. The following code scale
> the data and I have not been able to figure out how to change it so I get
> the centered data.
>  
> x <- c(1, 2, 3, 4, 5, 6, 7, 8)
> group <- c(1,1,1,2,2,2,2,2)
> unsplit(lapply(split(x,group),scale),group)
>
> I would appreciate your help.
>  
> Ashraf
> -----------------______________________________________
> M. Ashraf Chaudhary, Ph.D.
> Associate Scientist/Biostatistician
> Department of International Health
> Johns Hopkins Bloomberg School of Public Health
> 615 N. Wolfe St.  Room W5506
> Baltimore MD 21205-2179
>
> (410) 502-0741/fax: (410) 502-6733
>  <mailto:mchaudha at jhsph.edu> mchaudha at jhsph.edu
> Web:http://faculty.jhsph.edu/?F=Mohammad&L=Chaudhary
>  
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>   
-- 
Simon Blomberg, B.Sc.(Hons.), Ph.D, M.App.Stat.
Centre for Resource and Environmental Studies
The Australian National University
Canberra ACT 0200
Australia
T: +61 2 6125 7800 email: Simon.Blomberg_at_anu.edu.au
F: +61 2 6125 0757
CRICOS Provider # 00120C



More information about the R-help mailing list