Not to worry, I just worked it out (seems obvious now, apologies).

#Function for generating parameters
genparms<-function() {
list(
x = c(runif(1,2,3),runif(1,2,3))
,y = runif(1,2,3)
)
}

#Create N parameter sets
N<- 10
set<-rep(list("NA"),N)
for (i in 1:N) {
  set[[i]]<-genparms()
  }

> From: james_...@hotmail.com
> To: r-help@r-project.org
> Date: Wed, 28 Nov 2012 06:28:03 +0000
> Subject: [R] generating sets of parameters when some parameters are vectors
> 
> 
> 
> I'm trying to generate N lists of randomly selected parameter values. Some of 
> the parameters are vectors while other are single values. I've tried to use 
> the approach below but it doesn't work for parameter x, which should be a 
> vector. Thanks in advance! 
> James
> 
> 
>         #Define names of parameters in the list,
> parms<- list(
>   x=c(0,0),
>   y=0)
> 
> #Create N sets of randomly selected parameter values
> N<- 10
> set<-rep(list(parms),N)
> for (i in 1:N) {
>   set[[i]]["x"]=c(runif(1,1,2), runif(1,2,3))   ###Problem here
>   set[[i]]["y"]=runif(1,5,10)
>   }
>                                                                               
>   
>       [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help@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.
                                          
        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to