[英]Error importing multiple csv R: No such file or directory
I'm trying to read multiple csv files and store them in 1 dataframe. 我正在尝试读取多个csv文件,并将它们存储在1个dataframe中。 What I did is: 我所做的是:
files <- list.files(path="the path/", pattern="*.csv")
df = lapply(files, read.csv,sep = ";", encoding = "ISO-8859-1")
I've tried also sapply
. 我也试过sapply
。
I'm getting: 我越来越:
Error in file(file, "rt") : cannot open the connection cannot open file 'onefile.csv': No such file or directory 文件错误(文件,“ rt”):无法打开连接无法打开文件“ onefile.csv”:没有此类文件或目录
data.table
has a fast way to rbind
a list of data frames (which is what the lapply
returns), so using rbindlist
: data.table
有一个快速的方法来rbind
数据帧的列表(这是什么lapply
收益),因此使用rbindlist
:
library(data.table)
files <- list.files(path="the path/", pattern="*.csv", full.names = TRUE)
dt <- rbindlist(lapply(files, read.csv,sep = ";", encoding = "ISO-8859-1"),
use.names = TRUE, fill = TRUE)
To use fread
from data.table
in the lapply
: 要使用fread
从data.table
在lapply
:
dt <- rbindlist(lapply(files, fread, sep = ";", encoding = "Latin-1"),
use.names = TRUE, fill = TRUE)
To do this in base R (without using rbindlist
or fread
from data.table
): 要做到这一点在基R(不使用rbindlist
或fread
从data.table
):
df <- do.call(rbind, lapply(files, read.csv, sep = ";", encoding = "ISO-8859-1"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.