[R] Function to Normalize Numerical Vector in R
Daniel Malter
daniel at umd.edu
Tue Sep 8 07:19:51 CEST 2009
If you are looking for a function to standardize a variable so that it has
mean zero and unit variance:
std=function(x){if(length(which(is.na(x)))==0) (x-mean(x))/sd(x) else
(x-mean(x,na.rm=T))/sd(x,na.rm=T)
}
x=rnorm(100,3,5)
mean(x)
sd(x)
x2=std(x)
mean(x2)
sd(x2)
HTH,
Daniel
-------------------------
cuncta stricte discussurus
-------------------------
-----Ursprüngliche Nachricht-----
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von Gundala Viswanath
Gesendet: Monday, September 07, 2009 11:24 PM
An: r-help at stat.math.ethz.ch
Betreff: [R] Function to Normalize Numerical Vector in R
Is there any?
- G.V.
______________________________________________
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