I have a list of vectors and for each vector in the list I would like to extract the elements and use their values as arguments in a function. Here is the general idea of what I have come up with so far.
#Function to convert parametric values (stored in vector) to multivariate normal random data
ParamsToDat = function(X){
vec = X
MultN = rmvnorm(vec[4],c(vec[2],vec[3],matrix(c(vec[5],vec[1],vec[1],vec[6]), 2, 2, byrow = FALSE)))
return(MultN)
}
# Create list of randomly generated matrices based on parameters
GenData = function(MeanPre,MeanPost,Cov,SampSize,SampSD,IndVar1,IndVar2){
#Use GenParams function to generate list of vectors each of length 6
Params = GenParams(MeanPre,MeanPost,Cov,SampSize,SampSD,IndVar1,IndVar2)
#Use lapply function to create list of matrices of multivariate normal data
MatList = lapply(X = Params, FUN = ParamsToDat)
MultN = list(Matlist = Matlist, Params = Params)
return(MultN)
}
Each element in the list Params is a vector of length 6. I would like the function ParamsToDat to extract the elements of a vector in the list and use them as arguments to generate a matrix of multivariate normal data. This matrix will replace the vector from which the values were derived.
I am obviously messing something up with my ParamsToDat function or the lapply function or both since it is not working. Any Ideas how I could accomplish this?