sampling between two vectors


i have two vectors, say a <- 1:10 and b <- a^2
i would like a vector d containing :
runif(1,1,1) as first element
runif(1,2,4) as second element
runif(1,3,9) as third element
i have tried a fonction :
myalea <- function(u,v){return(runif(1,u,v))
but i can"t manage to apply it to vectors

i have done the job using the lentgh of the vectors and a loop but i wonder if there is something more "R"

the idea is to create alea distributions between two distributions
for example
x <- runif(1000,1,10)
y1 <- 2*x^2
y2<- 2.3*x^2
and y "between" y1 and y2


plusrunif <- function(x,y){


your answer shows me that there is no native R instruction for that
i guess \ should be a lambda function
and that map2_dbl applies this function to some vectors

so, thanks for the answer
would you have a website explaning a bit theorically why R cannot natively do it ?


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.