I'm trying to rescale a dataset of Rdata comprised between 0.17 and 0.00002589 to a range between 0 and 1. I would like the cumulative frequence to be equal to 1.
I tried to use the function rescale (from scales package) :
library(scales) t <-rescale(df, to = c(0,1)) #data go from [0.00002589:0.17] to [0.53:0.00004914] cumsum(t)= 4.24...
How do I correct my data in order to have cumsum equal to 1 ?
Thank you for your help.
1 Answer
You could add
t <- t / sum(t)
For example:
set.seed(42) df <- rnorm(n = 10, 1) t <- scales::rescale(df, to = c(0,1)) t <- t / sum(t) cumsum(t) #[1] 0.1740706 0.1740706 0.2575087 0.3652035 0.4523411 0.4935800 # [7] 0.6802913 0.7225612 0.9548573 1.0000000
ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJobXFxaGuAen2OoaawZaSkerOx0pyYpZ1dq66twcRmq6hlkWLAsbHCop2im12nrq%2BzxA%3D%3D