I have a dataframe with hundreds of columns, I want to rescale those columns to be between 0 and 1 but based on the min/max of all columns.
My data looks like this:
a<-c(1, 3, 4, 6, 8.7, 9, 10, 12, 19.3, 20)
b<-c(10, 30, 40, 60, 87, 90, 100, 120, 190, 200)
df<-data.frame(a=a, b=b)
> df
a b
1 1.0 10
2 3.0 30
3 4.0 40
4 6.0 60
5 8.7 87
6 9.0 90
7 10.0 100
8 12.0 120
9 19.3 190
10 20.0 200
So here the min is 1 and the max is 200.
I liked this function but It only can be applied to a vector :
rescale(*df*, to = c(0, 1), from = range(*df[,1:2]*, na.rm = TRUE, finite = TRUE))