RandVec expects both a and b to be single numbers, not numeric vectors
of length > 1.
You could create pairs of (a,b) values and cycle through them. There
are many ways
to do that. Here is one example. (Note that using a=0.1, b=.2, s=1,
n=2 is impossible to achieve, since two numbers bounded above by 0.2
cannot add to 1)

z <- list(c(.1,.2), (.2,.8))
sapply(1:length(z), \(i) RandVec(z[[i]][1], z[[i]][2], s=1, n=2, m=5))

HTH,
Eric


On Mon, Apr 21, 2025 at 5:28 PM Brian Smith <briansmith199...@gmail.com> wrote:
>
> Hi,
>
> There is a function called RandVec in the package Surrogate which can
> generate andom vectors (continuous number) with a fixed sum
>
> The help page of this function states that:
>
> a
>
> The function RandVec generates an n by m matrix x. Each of the m
> columns contain n random values lying in the interval [a,b]. The
> argument a specifies the lower limit of the interval. Default 0.
>
> b
>
> The argument b specifies the upper limit of the interval. Default 1.
>
> However in my case, the lower and upper limits are not same. For
> example, if I need to draw a pair of number x, y, such that x + y = 1,
> then the lower and upper limits are different.
>
> I tried with below code
>
> library(Surrogate)
>
> RandVec(a=c(0.1, 0.2), b=c(0.2, 0.8), s=1, n=2, m=5)$RandVecOutput
>
> This generates error with message
>
> Error in if (b - a == 0) { : the condition has length > 1
>
> Is there any way to generate the numbers with different lower and upper 
> limits?
>
> ______________________________________________
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide https://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to