Re: [R] Scalling/Centering the Data by an Index

From: Simon Blomberg <blomsp_at_ozemail.com.au>
Date: Thu 13 Jul 2006 - 16:54:31 EST

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@jhsph.edu> mchaudha@jhsph.edu
> Web:http://faculty.jhsph.edu/?F=Mohammad&L=Chaudhary
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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

______________________________________________
R-help@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
Received on Thu Jul 13 16:58:36 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 13 Jul 2006 - 18:14:20 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.