【问题标题】:read a csv file in a zipped folder with R without unzipping使用R读取压缩文件夹中的csv文件而不解压缩
【发布时间】:2017-10-11 07:57:13
【问题描述】:

我有一个名为 master.zip 的压缩文件,其中包含 2 个 CSV 文件:file1.csvfile2.csv

我只想阅读file1.csv,例如:read_csv('master/file1.csv'),但不必解压缩master.zip。如何使用 R 实现这一目标?

【问题讨论】:

标签: r csv zip


【解决方案1】:

你只需要使用原生函数unz()。假设master.zip 在您的工作目录中,

# just a list of files inside master.zip
master <- as.character(unzip("master.zip", list = TRUE)$Name)
# load the first file "file1.csv"
data <- read.csv(unz("master.zip", "file1.csv"), header = TRUE,
                 sep = ",") 

【讨论】:

    猜你喜欢
    • 2010-09-05
    • 2013-03-09
    • 1970-01-01
    • 2010-12-14
    • 1970-01-01
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多