开发者

How to read multiple excel sheets in R programming? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answere开发者_JS百科d in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I have an excel file which contains 400 sheets. How can I load this excel file to R using read.xls function? Please provide sample code for this.


I'm just assuming you want it as all one data.frame() and that all the sheets contain the same data.

library(xlsReadWrite) 
sheets <- c("Sheet 1","Sheet 2", "Sheet 3")

df <- data.frame()

for (x in 1:400) 
df <- rbind(df, read.xls("filename.xls", sheet=sheets[x]))
}

If each sheet is it's own unique data.frame() you'll probably want to put them in a list. Otherwise you can use assign() if you want them as objects in the environment.

sheet_list <- list()
for(x in 1:400) {
sheet_list[[x]] <- read.xls("filename.xls", sheet=sheets[x])
} 

Or, without a for loop:

sheet_list <- lapply(sheets, function(x) read.xls("filename.xls",sheets=x)) 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜