Last active
March 28, 2017 23:24
-
-
Save frbl/c306dbab940fced651488767ab86dbd7 to your computer and use it in GitHub Desktop.
Sample from uniform distribution given a list of intervals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data <- c(1,2,1,3,2,1,2,3) | |
intervals <- c(0.1, 0.3, 0.6,1) | |
runif(data, intervals[data], intervals[data+1]) | |
# Test if the output is correct: | |
check <- all(unlist(lapply(1:length(data), function(i) {res[i] >= intervals[data[i]] & res[i] <= intervals[data[i] + 1]}))) | |
expect_true(check) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment