I'm trying to lapply a function over a list. Because my function intends to output 2 objects, I'm running into a problem. For each item in the list, running the function only outputs results from the second object.
Here is a vastly simplified example.
test<-function(x){
a<-x+4
b<-x/34
}
list<-c(3,4,5,6,6)
lapply(list,test)
# Outputs b:
[[1]]
[1] 0.08823529
[[2]]
[1] 0.1176471
[[3]]
[1] 0.1470588
[[4]]
[1] 0.1764706
[[5]]
[1] 0.1764706
How to I get the function to output both a and b?
testfunction, add a third line:return(a = a, b = b)return(c(a = a, b = b))(orlistdepending on preference). Butreturn()is a bit pointless on the last line, justc(a = a, b = b)would be fine.list, actually. as inreturn(list(a=a, b=b))