我在目录中有一系列csv文件。
我试过了:
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
cannot open file '11NORTHBOUND.csv': No such file or directory
但是,我收到以下错误:
SELECT first.ID,
second.Place,
CASE WHEN mytable.ID IS NULL THEN 0 ELSE 1 END AS YesNo
FROM (
SELECT DISTINCT ID
FROM mytable
) first
CROSS JOIN (
SELECT DISTINCT Place
FROM mytable
) second
LEFT JOIN mytable
ON mytable.ID = first.ID
AND mytable.Place = second.Place
ORDER BY first.ID,
second.Place
如您所见,它正确读取文件名(11NORTHBOUND.csv)。出现此错误的可能原因是什么?
答案 0 :(得分:1)
您与文件不在同一目录中。使用getwd()
验证。以下内容可能有效:
fileslist <- list.files(path="/Users/joker/csv_test/", pattern=".csv")
MyFileList <- lapply(fileslist, function(i) read.csv(paste0("/Users/joker/csv_test/", i))
要预先测试,请使用
testFile <- read.csv(paste0("/Users/joker/csv_test/", fileslist[1]))
答案 1 :(得分:1)
您的sapply行中文件的路径不正确,因为您的路径未包含在文件名向量中。 files.list()有一个full.names选项,默认为FALSE。如果你使用full.names = TRUE(这样&#34;目录路径被添加到文件名之前,为了给出相对文件路径&#34;),代码将起作用。
fileslist <- list.files(path="/Users/joker/csv_test/", pattern=".csv", full.names=TRUE)
sapply(fileslist, read.csv)