I want to write a little function to generate samples from appropriate distributions, something like:
makeSample <- function(n,dist,params)
values <- makeSample(100,"unif",list(min=0,max=10))
values <- makeSample(100,"norm",list(mean=0,sd=1))
Most of the code works, but I'm having problems figuring out how to pass the named parameters for each distribution. For example:
params <- list(min=0, max=1)
runif(n=100,min=0,max=1) # works
do.call(runif,list(n=100,min=0,max=1)) # works
do.call(runif,list(n=100,params)) # doesn't work
I'm guessing I'm missing a little wrapper function somewhere but can't figure it out.
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…