从列表中表达多个对象/元素

时间:2016-03-01 20:31:56

标签: r list regression

我正在学习<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSource1" GridLines="Vertical"> <AlternatingRowStyle BackColor="#DCDCDC" /> <Columns> <asp:BoundField DataField="Group_Name" HeaderText="Group" SortExpression="Group_Name" /> <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" /> <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" /> <asp:BoundField DataField="First_Phone_Number" HeaderText="1st Number" SortExpression="First_Phone_Number" /> <asp:BoundField DataField="Second_Phone_Number" HeaderText="2nd Number" SortExpression="Second_Phone_Number" /> <asp:BoundField DataField="Fax_Phone_Number" HeaderText="Fax Number" SortExpression="Fax_Phone_Number" /> <asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes" /> <asp:TemplateField HeaderText="Attachments" ItemStyle-Width="30"> <ItemTemplate> <asp:HyperLink runat="server" NavigateUrl='<%# Eval("Attachments", "~/HtmlAttachmentPage.html?Id+{0}") %>' Text='<%# Eval("Attachments") %>' /> </ItemTemplate> </asp:TemplateField> </Columns> 并提出以下问题。我运行以下代码来找到最佳的多项式模型。

R

代码有效。但是关于set.seed(123) library(ISLR) ##################################### # polynomial rss <- rep(NA, 15) fits <- list() for (i in 1:15) { fits[[i]] <- lm(mpg ~ poly(displacement, i), data = Auto) rss[i] <- deviance(fits[[i]]) } rss anova(fits[[1]], fits[[2]], fits[[3]], fits[[4]], fits[[5]], fits[[6]], fits[[7]], fits[[8]], fits[[9]], fits[[10]], fits[[11]], fits[[12]], fits[[13]], fits[[14]], fits[[15]]) 的最后一部分看起来似乎很乏味,如果适合包含大量元素则不实用。如何简化?

1 个答案:

答案 0 :(得分:2)

通常,如果要将值列表转换为单独的参数,请使用do.call。因此,对于您的示例,您将运行

do.call("anova", fits)