[R] standardization

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jul 13 11:20:10 CEST 2007


On Fri, 13 Jul 2007, David Barron wrote:

> Try having a look at the scale and sweep functions.

sweep applies to arrays, not data frames, and scale converts to a matrix.

For a data frame

df2 <- df1
df2[] <- lapply(df1, function(x) {r <- range(x, na.rm=TRUE);
                                   (x-r[1])/diff(r)})

seems simple enough.

> On 13/07/07, Amir_17 <amirhendi at yahoo.com> wrote:
>> Hi
>>   I have dataframe which contain 5 columns and 1000 records. I want standard each cell.
>>   I want range each column  between 0 and 1 . I think i must use loop?
>>   could you help me?

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list