jeudi 10 février 2022

How to create random number in ifelse function?

I would like to implement random numbers for the time values equal to 0 (time == 0) and keep other time values as given.

set.seed(123)
 df$time.new <- ifelse(df$time == 0, sample(0.2:0.8, replace=F), df$time)

Using the formula only 0.2 is created.




Aucun commentaire:

Enregistrer un commentaire