1

我需要什么代码将多个数据集读入 R ?

对于我使用的单个数据集:

File <- read.csv("C:\MyFile.CSV", header=T)

但我需要比较多达 20 个不同的数据集。

提前致谢 !

4

1 回答 1

1

我会将所有 CSV 文件放在一个目录中,创建一个列表并执行循环以从列表中的目录中读取所有 csv 文件。

setwd("~/Documents/")
ldf <- list() # creates a list
listcsv <- dir(pattern = "*.csv") # creates the list of all the csv files in the directory
for (k in 1:length(listcsv)){
 ldf[[k]] <- read.csv(listcsv[k])
}
str(ldf[[1]]) 
于 2013-06-24T09:19:48.530 回答