I have a dataframe:
priors <- data.frame(dist = c('lnorm', 'beta', 'gamma'),
a = c(0.5, 1, 10),
b = c(0.4, 25, 4),
n = c(100, 100, 100)
)
and I would like to take n samples from the distribution with parameters a and b.
I have written this function:
pr.samp <- function(n,dist,a,b) {eval (parse (
text =
paste("r",dist,"(",n,",",a,",",b,")",sep = "")
))}
I would like to know:
- is there a better approach?
- how would I use one of the apply functions to run this on each row?
- do I have to convert the dataframe to a matrix to do this?
Thanks in advance!