I have a dataframe with two columns, low and high. I would like to create a new variable that is a randomly selected value between low and high (inclusive and equal probability) using dplyr. I have tried
library(tidyverse)
data_frame(low = 1:10, high = 11) %>%
mutate(rand_btwn = base::sample(seq(low, high, by = 1), size = 1))
which gives me an error since seq
expects scalar arguments.
I then tried again using a vectorized version of seq
seq2 <- Vectorize(seq.default, vectorize.args = c("from", "to"))
data_frame(low = 1:10, high = 11) %>%
mutate(rand_btwn = base::sample(seq2(low, high, by = 1), size = 1))
but this does not give me the desired result either.