R coding for random value with contraint

Home / Uncategorized / R coding for random value with contraint

Question:
I want to know R code for generating 1000 random values for x and y between 1 to 7 such that x<=y and all the numbers are identically distributed.


Answer:
With float number
x <- c() y <- c() for (i in 1:1000){ x[i] <- runif(1, 1, 7) y[i] <- runif(1, x[i], 7) // print or do something you want here } With integer number x <- c() y <- c() for (i in 1:1000){ x[i] <- sample(1:7, 1) y[i] <- sample(x[i]:7, 1) // print or do something you want here } You can try it. Read more

Leave a Reply

Your email address will not be published. Required fields are marked *