list - R: Applying function to DataFrame -


i have following code:

library(ecdat) data(fair) fair[1:5,]  x1 = function(x){   mu = mean(x)   l1 = list(s1=table(x),std=sd(x))   return(list(l1,mu)) }  mylist <- as.list(fair$occupation,                fair$education)  x1(mylist) 

what wanted x1 outputs result items selected in mylist. however, in mean.default(x) : argument not numeric or logical: returning na.

you need use lapply if passing list function

output<-lapply(mylist,fun=x1) 

this process function x1 each element in mylist , return list of results output.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -