I have data frame with 0 values, i want to convert each zero to a random value between 0.1 and 0.5
X2 X3 X4 X5
390 0 0.000 0.00 0.00
7433 0 27.839 0.00 0.00
5579 0 0.000 151.95 0.00
to be
X2 X3 X4 X5
390 0.1 0.200 0.43 0.29
7433 0.3 27.839 0.24 0.30
5579 0.4 0.200 151.95 0.50
Could try
indx <- df == 0L
df[indx] <- runif(sum(indx), 0.1, 0.5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With