I wanted to ask if someone knows a workaround of how I can dynamically assign arguments to R's sampling functions, i.e., I want to write a list with different names, say "mean" and "sd", and the elements of both of these sub-lists contain the corresponding numeric values for these parameters I want to have. As an example, I would like to do this:
#Distribution of Interest
SamplingDistribution <- rnorm
#Parameters of Interest for Normal Distribution
Parameters <- list(mean = c(1, -1),
sd = c(1, 2)
)
#Not Working Example
SamplingDistribution (n = 1,
for(i in 1:length(Parameters) ){
names(Parameters)[i] <- Parameters[i]
}
)
So ideally i just clarify the sampling distribution of interest at the beginning and then can put any argument that I want (in any order) in the Parameters list. Then the for loop just loops through the names of the parameters lists, and assigns the corresponding numeric values to the sample. Thanks to your input!
Best regards,
Edit: I get that I can just use the listnames in the rnorm function, but the focus of this question is really to somehow dynamically assign that, i.e. I can just expand the parameter list with more arguments and I dont have to assign anything new to the sampling procedure. I tried already around quite a bit with message/pasteo/cat/..., but the rnorm() function seems to not really accept any of these ...