这是一个后续问题这一个.将.xlsx文件读入R 的最快方法是什么?
我library(xlsx)用来读取36个.xlsx文件的数据.有用.然而,问题在于这非常耗时(超过30分钟),尤其是在考虑每个文件中的数据不是那么大时(每个文件中的矩阵大小为3*3652).为此,请问有更好的处理这样的问题吗?还有另一种快速阅读.xlsxR的方法吗?或者我可以快速将36个文件放入单个csv文件然后读入R?
而且,我才意识到readxl不能写xlsx.是否有对应的处理写作而不是阅读?
"对那些投票反对的人的回应":
这个问题是关于事实,而不是所谓的"自以为是的答案和垃圾邮件",因为速度是时间和时间是事实但不是意见.
进一步更新:
或许可以用简单的语言向我们解释为什么某些方法的工作速度比其他方法快得多.我当然对此感到困惑.
Mar*_*ann 14
这是一个小的基准测试.结果:使用标准设置readxl::read_xlsx,平均速度是openxlsx::read.xlsx不同行数(n)和列数()的两倍p.
options(scipen=999) # no scientific number format
nn <- c(1, 10, 100, 1000, 5000, 10000, 20000, 30000)
pp <- c(1, 5, 10, 20, 30, 40, 50)
# create some excel files
l <- list() # save results
tmp_dir <- tempdir()
for (n in nn) {
for (p in pp) {
name <-
cat("\n\tn:", n, "p:", p)
flush.console()
m <- matrix(rnorm(n*p), n, p)
file <- paste0(tmp_dir, "/n", n, "_p", p, ".xlsx")
# write
write.xlsx(m, file)
# read
elapsed <- system.time( x <- openxlsx::read.xlsx(file) )["elapsed"]
df <- data.frame(fun = "openxlsx::read.xlsx", n = n, p = p,
elapsed = elapsed, stringsAsFactors = F, row.names = NULL)
l <- append(l, list(df))
elapsed <- system.time( x <- readxl::read_xlsx(file) )["elapsed"]
df <- data.frame(fun = "readxl::read_xlsx", n = n, p = p,
elapsed = elapsed, stringsAsFactors = F, row.names = NULL)
l <- append(l, list(df))
}
}
# results
d <- do.call(rbind, l)
library(ggplot2)
ggplot(d, aes(n, elapsed, color= fun)) +
geom_line() + geom_point() +
facet_wrap( ~ paste("columns:", p)) +
xlab("Number of rows") +
ylab("Seconds")
Run Code Online (Sandbox Code Playgroud)