r - Extractor function for "call" in lm -
r - Extractor function for "call" in lm -
is there generic extractor function linear models pull call model? i'm looking apply model across list of dataframes, extract phone call model (i'm doing bunch of times on many info frames , models, looking easy way maintain track of model which)
example data:
set.seed(1234) library(plyr) info <- data.frame( biz = sample(c("telco","shipping","tech"), 50, replace = true), part = sample(c("mideast","americas"), 50, replace = true), orders = sample(1:50, 50, replace=true), revenue = sample(100:150, 50, replace=true) )
now if wanted apply simple lm across data, "region" :
modlist <- dlply(data, 'region', function(df){ summary(lm(revenue ~ orders, data=df)) })
for has standard extractor function, "coefficients" = "coef", straightforward:
coefs <- ldply(modlist, coef)
but can't find way extract "call", e.g., "lm(formula = revenue ~ orders, info = df)". ideas?
just write own function extract phone call in same way stats:::print.lm
does
coefs <- ldply(modlist, function(x) deparse(x$call))
r
Comments
Post a Comment