简体   繁体   English

使用单个代码读取多个 .csv 文件

[英]Reading the multiple .csv files with single code

There is a zip archive stored on the internet.有一个存储在互联网上的 zip 存档。 I want to download it to my computer and read it into R with the single code.我想把它下载到我的电脑上,然后用单个代码将它读入 R。

someURL<-"http://www.stat.ucla.edu/~vlew/datasets/spssSTUFF.zip"
download.file(someURL,"ucpay.zip")
unzip("ucpay.zip", exdir = "ucpaydata")
list.files("ucpaydata")

I have downloaded the files, now i have a problem, how could I read them all into R using at most one line of code (no semi-colons allowed but nesting and piping are OK).我已经下载了文件,现在我遇到了一个问题,我怎么能最多使用一行代码将它们全部读入 R(不允许使用分号,但嵌套和管道都可以)。

Here is one way to do it.这是一种方法。

files = list.files("ucpaydata")
Df = do.call(rbind(lapply(files, function(x) {read.csv(x, header = T)})))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM