break dataframe into subsets by factor values, send to function that returns glm class, how to recom

Posted by Alex Holcombe on Stack Overflow See other posts from Stack Overflow or by Alex Holcombe
Published on 2010-06-03T23:11:08Z Indexed on 2010/06/06 22:52 UTC
Read the original article Hit count: 316

Filed under:
|

Thanks to Hadley's plyr package ddply function we can take a dataframe, break it down into subdataframes by factors, send each to a function, and then combine the function results for each subdataframe into a new dataframe.

But what if the function returns an object of a class like glm or in my case, a c("glm", "lm"). Then, these can't be combined into a dataframe can they? I get this error instead

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class 'c("glm", "lm")' into a data.frame

Is there some more flexible data structure that will accommodate all the complex glm class results of my function calls, preserving the information regarding the dataframe subsets?

Or should this be done in an entirely different way?

© Stack Overflow or respective owner

Related posts about r

    Related posts about plyr