Thanks for your response! I was trying something like this last night (still very raw):
library(tidyverse)
# 01) Determine min and max for all columns -------------------------------
mincars <-
mtcars %>% sapply(max)
maxcars <-
mtcars %>% sapply(min)
# 2) Create the random values for each respective column" -----------------
output <-
purrr::map2(.x = mincars, .y = maxcars, .f = function(x,y)
{
sample(c(x:y),1)
# if(x%%1==0){
# sample(c(x:y),1)
# } else {
# sample(c(x:y),1)
# }
}
) %>% unlist()
# 3) Combine with the original --------------------------------------------
output_data <- mtcars %>% rbind(output)
# 4) WIP
custom_mapper <-
function(mincars,maxcars, repeter){
purrr::map2(.x = mincars, .y = maxcars, .f = function(x,y)
{
sample(c(x:y),1)
# if(x%%1==0){
# sample(c(x:y),1)
# } else {
# sample(c(x:y),1)
# }
}
) %>% rep( times = repeter)
}
output <-
custom_mapper(mincars,maxcars,5) %>% unlist() %>%
matrix( nrow = 5) %>% as.data.frame()
names(output) <- names(mtcars)
output_data <- mtcars %>% rbind(output)
I think the approaches are similar. I was going to see if the respective value had no remainder to determine whole or decimal number. I knew it likely will have to need some map function given we have multiple inputs. I just had to figure out how best to reduce my list into vector and into rows (your approach definitely seems a lot cleaner there!).