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

Rui Barradas ruipbarradas at sapo.pt
Tue Oct 2 12:38:49 CEST 2012


Hello,

Try the following.

fun <- function(x){
     a <- min(x)
     b <- max(x)
     (x - a)/(b - a)
}

mat <- matrix(rnorm(12), ncol=3)
apply(mat, 2, fun)

Hope this helps,

Rui Barradas
Em 02-10-2012 10:51, Rui Esteves escreveu:
> 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.




More information about the R-help mailing list