do.L | R Documentation |
Standardizes all values in a vector to the unit vector ([0,1]) using local min and max
do.L(v, fun = range, na.rm = T)
v |
a vector of values |
fun |
a function that will return the minimum and maximum values to use to scale v;
defaults to |
na.rm |
Logical: should NA be removed? defaults to |
This is an alternative to performing a L normalization over the full matrix.
if the minimum and the maximum values returned after applying fun
are the same, do.L
will return 0.
A vector of values of the same length as x, scaled to the unit vector.
Yann Abraham
data(iris) mat <- iris[,c('Sepal.Length','Sepal.Width','Petal.Length','Petal.Width')] scaled <- apply(mat,2,do.L) summary(scaled) # all values are between [0,1] scaled2 <- apply(mat,2,do.L,fun=function(x) quantile(x,c(0.025,0.975))) summary(scaled2) # all values are between [0,1] plot(scaled,scaled2, col=rep(seq(1,ncol(scaled)),each=nrow(scaled)), pch=16) legend('topleft',legend=dimnames(scaled)[[2]],col=seq(1,ncol(scaled)),pch=16,bty='n')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.