慕容森
下面是一种使用普雷一揽子:d <- data.frame(
state = rep(c('NY', 'CA'), 10),
year = rep(1:10, 2),
response= rnorm(20))library(plyr)# Break up d by state, then fit the specified model to each piece and# return a listmodels
<- dlply(d, "state", function(df)
lm(response ~ year, data = df))# Apply coef to each model and return a data frameldply(models, coef)# Print the summary of each
modell_ply(models, summary, .print = TRUE)