簡體   English   中英

R:無法讀取粘貼文件名的csv數據

[英]R: can't read csv data of pasted file name

我正在編寫一個通用腳本來讀取在線工具的數據。 到目前為止,這是我的代碼:

d <- list.files("E:/...path.../demo_subjects")
d <- rep(d, each=4)
f <- c("0.csv", "1.csv", "2.csv", "3.csv")
l <- paste0(d,"/", f)
n <- paste0("E:/...path.../demo_subjects/",l)

for (i in 1:length(d)) {
  x[i] <- read.csv(n, sep=",", header = TRUE)
}

返回此錯誤:

file(file,“ rt”)中的錯誤:無效的'description'參數

經過密集的谷歌搜索,我還沒有找到答案。 對於某些人來說,問題與無效的文件路徑有關,但是

file.exists(n)

返回所有TRUE。

嘗試這個:

path <- 'yourpath'
d <- list.files(path)
d <- rep(d, each=4)
f <- c("0.csv", "1.csv", "2.csv", "3.csv")
l <- paste0(d,"/", f)
n <- paste0(path,l)
x <- list()

for (i in 1:length(d)) {
  x[[i]] <- read.csv(n[i], sep=",", header = TRUE)
}

據我所知,read.csv中的參數文件未向量化,因此您可能忘記了索引n:...... read.csv(n [i],sep =“,” ....... ..

此外,您必須將此輸出分配給列表的元素! 因此,請使用雙束線符為x編制索引,並在for循環之前初始化一個空列表(x <-list())。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM