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