Scaling a numeric matrix in R with values 0 to 1 Scaling a numeric matrix in R with values 0 to 1 r r

Scaling a numeric matrix in R with values 0 to 1


Try the following, which seems simple enough:

## Data to make a minimal reproducible examplem <- matrix(rnorm(9), ncol=3)## Rescale each column to range between 0 and 1apply(m, MARGIN = 2, FUN = function(X) (X - min(X))/diff(range(X)))#           [,1]      [,2]      [,3]# [1,] 0.0000000 0.0000000 0.5220198# [2,] 0.6239273 1.0000000 0.0000000# [3,] 1.0000000 0.9253893 1.0000000


And if you were still to use scale:

maxs <- apply(a, 2, max)mins <- apply(a, 2, min)scale(a, center = mins, scale = maxs - mins)


Install the clusterSim package and run the following command:

normX = data.Normalization(x,type="n4");