[R] Is there any R function for data normalization?

Joshua Wiley jwiley.psych at gmail.com
Tue Oct 2 12:02:54 CEST 2012

Hi Rui,

It doesn't really need one...

doit <- function(x) {(x - min(x, na.rm=TRUE))/(max(x,na.rm=TRUE) -
min(x, na.rm=TRUE))}

# use lapply to apply doit() to every column in a data frame
# mtcars is built into R
normed <- as.data.frame(lapply(mtcars, doit))
# very that the range of all is [0, 1]
lapply(normed, range)



On Tue, Oct 2, 2012 at 2:51 AM, Rui Esteves <ruimaximo at gmail.com> wrote:
> Hello,
> I have a matrix with values, with columns c1..cn.
> I need the values to be normalized between 0 and 1 by column.
> Therefor, the 0 should correspond to the minimum value in the column c1 and
> 1 should correspond to the maximum value in the column c1.
> The remaining columns should be organized in the same way.
> Does a function in R exists for this purpose?
> Thanks,
> Rui
>         [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, Statistical Consulting Group
University of California, Los Angeles

More information about the R-help mailing list