我有一个zip文件夹,其中包含332 csv文件。我必须首先使用R解压缩它,然后将其保存到目录中。我怎么做?

时间:2016-05-13 10:53:14

标签: r

我试过 - read.zip(file ="C:/Users/dm/Downloads/rprog-data-specdata.zip")

和 - l = list.files("C:/Users/dm/Downloads/rprog-data-specdata") read.csv(l[1:332])

但它不能正常工作

1 个答案:

答案 0 :(得分:4)

除非你真的希望它们都被提取出来,否则你不必这样做。您可以直接从存档中读取它们:

# you 
zipped_csvs <- "rprog-data-specdata.zip"

# get data.frame of file info in the zip
fils <- unzip(zipped_csvs, list=TRUE)

# read them all into a list (or you can read individual ones)
dats <- lapply(fils$Name, function(x) {
  read.csv(unzip(zipped_csvs, x), stringsAsFactors=FALSE)
})