我正在阅读一些csv文件来创建数据框,并使用以下代码向文件名后附加一列:
wd <- "Working directory"
file_list <- list.files(wd)
### Function: read data ###
read_data <- function(file){
d <- read.csv(paste(wd,file,sep=""), stringsAsFactors = FALSE, strip.white = TRUE, na.strings = c("NA","")); # read in every file in the working directory
d$FileName <- substr(file,20,29); # append part of file name
d # return the dataframe
}
### Call rbind: merge data ###
df <- do.call(rbind, lapply(file_list,read_data))
但是出现了这个错误:
Error in `$<-.data.frame`(`*tmp*`, "FileName", value = "2016010209") :
replacement has 1 row, data has 0
我做错了什么?
干杯
答案 0 :(得分:0)
始终检查数据!该文件已损坏,因此为空! 谢谢你的帮助!