如何将R中的anova结果导出到excel文件?

时间:2017-09-28 10:27:18

标签: r anova

# Create Excel Files for Linear Regression and StepAIC
MyExcelFile <- XLConnect::loadWorkbook("Anova_Results.xlsx", create = TRUE)


#Build the Regression model
LinReg_Model<-function(x) {
  Countries <- c("abc,def,ghi")
  for (val in Countries) {
    createSheet(MyExcelFile, val) 
    #create a sheet and name it with country name 
    set.seed(111)
    LinReg <- lm(Sales ~.,data=datadf)
    Lin_Anova <- anova(LinReg)
    writeWorksheet(MyExcelFile1, Lin_Anova, sheet = val, startRow = 1, startCol = 1) # write results of Model Summary
    }
  saveWorkbook(MyExcelFile1) 
  }

# run the function to check
LinReg_Model()

运行上面的代码后,我确实得到了结果,但excel表没有捕获变量的名称,如附图中所示。 仅供参考,我正在使用XLConnect包将数据写入excel。  enter image description here

0 个答案:

没有答案