Iterating function for building a list
I have a list of functions:
func1 <- function(u)
{
list(val=u, ref="XX1")
}
func2 <- function(u)
{
list(val=u*u, ref="XX55")
}
func3 <- function(u)
{
list(val=u-1, ref="XX3")
}
And I want to get a result like this with u=2
:
list(XX55=4, XX3=1, XX1=2)
For now, I continue like this:
funcs = c(func1, func2, func3)
temp = llply(funcs, function(f) f(2))
res = llply(temp, function(u) u$val)
names(res) = llply(temp, function(u) u$ref)
res
But maybe there is a more elegant / concise way to continue?
+3
source to share