我正在运行以下代码..。
#Create a list of all the files
file.list <- list.files(path="~/R/natural-language-processing/class-notes", pattern=".csv")
#Loop over file list importing them and binding them together
D1 <- do.call("rbind",lapply(file.list, read.csv, header = TRUE, stringsAsFactors = FALSE))这是我在上面运行do.call行时遇到的错误。
文件中的错误(文件,"rt"):无法打开连接
我试过重新设置我的wd。我现在的getwd()是
~/R/natural-language-processing我已经看穿了另一个
文件中的错误(文件,“rt”):无法打开连接
发布于 2018-03-04 00:41:30
很可能您试图从工作目录中打开文件,而不是在其中调用list.files的目录。相反,试着
D1 <- do.call("rbind",
lapply(paste0("~/R/natural-language-processing/class-notes/",
file.list),
read.csv, header = TRUE, stringsAsFactors = FALSE))或者,可以将full.names参数设置为list.files中的TRUE以获得完整的路径:
file.list <- list.files(path="~/R/natural-language-processing/class-notes",
pattern=".csv", full.names = TRUE)发布于 2018-03-04 00:39:06
read.csv正在您的工作目录中查找文件名。通过将工作目录更改为"C:/Users/Bob/Documents/R/natural-language-processing/class-notes",,您的代码应该工作得很好。
代码:
setwd("C:/Users/Bob/Documents/R/natural-language-processing/class-notes")然后重新运行你的代码。
发布于 2019-05-11 17:48:14
我只是花了很多时间想弄清楚我的代码出了什么问题.
如果你使用的是窗口,这似乎很简单。
当您将文件命名为"blabla.txt“时,windows将其命名为”blabla.txt.txt“..CSV文件也是如此,所以如果您将其称为"001.csv“,windows将创建一个名为"001.csv.csv”的文件。
因此,当您创建您的read.table("/absolute/path/of/directory/with/required/001.csv")文件时,只需将其重命名为"001“,并使用read.table(”/absolute/path/of/directory/with/required/001.csv“)在R中打开它。
对我来说很管用。
https://stackoverflow.com/questions/49090622
复制相似问题