How can I extract multiple zip files and read those csvs in R? [duplicate]

Deadly 提交于 2019-12-01 19:55:56

I often use the ldply function from the plyr package to read or do stuff with multiple files.

library(plyr)

# get all the zip files
zipF <- list.files(path = "/your/path/here/", pattern = "*.zip", full.names = TRUE)

# unzip all your files
ldply(.data = zipF, .fun = unzip, exdir = outDir)

As Richard pointed out this is not complete (to much coffee in the morning is also not good).

# get the csv files
csv_files <- list.files(path = outDir, pattern = "*.csv")

# read the csv files
my_data <- ldply(.data = csv_files, .fun = read.csv)

I liked the comment of Joel a lot. I'am used to using the plyr package so much that I forgot that you can also use the sapply function. Maybe even better to use!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!