Given the following function which returns a function
get_function <- \(model) {
meanlog <- model[['Mean']]
sdlog <- model[['SD']]
\(x){ dlnorm(x,
meanlog = meanlog,
sdlog = sdlog)
}
}
When I use the get_function
as follow:
func <- distributions[['866064']] |> get_function()
func return the correct function. All work as expected, Great!
However, when I try to use the get_function
in a for loop, like so:
output <- NULL
for(product in names(distributions)) {
output[[product]] <- distributions[[product]] |> get_function()
}
All the functions loaded in the output list are the same, where they should be different because the model associated with each product in the distributions list is different.
What am I doing wrong? How can I get the correct function loaded into the output list based on the different models in the distributions list?