r - How to get lapply to output 2 objects obtained from a function -


i'm trying lapply function on list. because function intends output 2 objects, i'm running problem. each item in list, running function outputs results second object.

here 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 function output both , b?

the function returning last line should. try:

test<-function(x){ a<-x+4 b<-x/34 return(c(a,b)) } list<-c(3,4,5,6,6) lapply(list,test) 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -