Reputation: 351
Problem: In VAR how can I replace every value of 1 with a random number between 1.1 and 7.1 and every value of 2 with a random number between 7.2 and 10.1?
i = seq(1,2,by = 1)
j = c(0.30,0.70)
VAR = sample(i, size = 100, replace = TRUE, prob = j)
Upvotes: 0
Views: 63
Reputation: 388817
We can use runif
to generate random numbers between min and max value.
VAR[VAR == 1] <- runif(sum(VAR == 1), 1.1, 7.1)
VAR[VAR == 2] <- runif(sum(VAR == 2), 7.2, 10.1)
Upvotes: 2