[R] function runif in for loop
Johannes Radinger
JRadinger at gmx.at
Wed Aug 10 15:45:15 CEST 2011
-------- Original-Nachricht --------
> Datum: Wed, 10 Aug 2011 09:38:38 -0400
> Von: Duncan Murdoch <murdoch.duncan at gmail.com>
> An: Johannes Radinger <JRadinger at gmx.at>
> CC: r-help at r-project.org
> Betreff: Re: [R] function runif in for loop
> On 10/08/2011 7:28 AM, Johannes Radinger wrote:
> > Hello,
> >
> > I'd like to perform a regression using MCMCregress (MCMCpack).
> > One variable therefore should be a function rather than a variable:
> >
> > I want to use X as an input and X should be defined as a random number
> between to values. Therefore I want to use the function runif like:
> > X<-(1, Xa, Xb) but it seems that runif doesn't allow to use vectors.
> > So I think I've to calculate the new vector X by using a for loop.
>
> runif() does allow vectors. Assuming Xa and Xb are vectors of length n,
> then
>
> X <- runif(n, Xa, Xb)
Thank you very much, I just got confused with the n, as I wanted always only one value between Xa and Xb.
So far my solution based on your suggestion is:
X <- runif(length(Xa), Xa, Xb)
/johannes
>
> will work. (Xa and Xb don't both have to be vectors; values will be
> recycled as necessary.)
>
> Duncan Murdoch
> > I tried "for (i in 1:length(lT)) T<-runif(1,lT,uT)" but that doesn't
> work.
> > What is the correct for-loop function to create this new
> vector/variable?
> >
> > Can I use that function then as an input for MCMCregress?
> >
> > thank you
> >
> > Johannes
> >
> > --
> >
> > ______________________________________________
> > R-help at r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
--
More information about the R-help
mailing list