我尝试使用下面的代码将列名插入到我的R代码中,并在运行实际代码时继续收到此错误: match.names(clabs,names(xi))出错: 名称与以前的名称不匹配
有人知道如何解决这个问题吗?我已经检查了关于如何解决这个问题的堆栈溢出的其他文章,但没有人在代码中发布WHERE来输入解决方案,因此我无法正确修复我的代码。注意:我遗漏了目录信息,所以请关注代码的实际内容。谢谢!
for (fle in i.want.these.files){
#read in file to parse
mydata <- read.table(paste(my.in.dir,fle,sep = '/'), sep="|", allowEscapes =
TRUE, fill = FALSE, stringsAsFactors = F, quote = "")
mydata[,1] <- gsub(" ", "", mydata[,1])
empty_rows <- which(nchar(mydata[,1]) == 0)
non_empty_rows <- which(nchar(mydata[,1]) != 0)
mydata2 <- NULL
for (i in 2:length(non_empty_rows)) {
var <- mydata[non_empty_rows[i],12]
for (n in (non_empty_rows[i]+1):(min(non_empty_rows[i+1]-1,
max(non_empty_rows), na.rm =T))) {
var <- paste0(var, mydata[n, 12])
}
mydata2 <- rbind(mydata2,
cbind(mydata[non_empty_rows[i], 1:11], var))
colnames(mydata2) <- c("A","B","C","D","E","F","G","H","I","J","K","L")
}
write.table(mydata2, file=paste(my.out.dir,"rolled_message_test1.csv",
sep="/"), sep=",", col.names = FALSE, row.names = FALSE)
}