我正在尝试读取具有重复行名的csv文件,但无法。我收到的错误消息是Error in read.table(file = file, header = header, sep = sep, quote = quote, : duplicate 'row.names' are not allowed.
我使用的代码是:

S1N657 <- read.csv("S1N657.csv",header=T,fill=T,col.names=c("dam","anim","temp"))

我的数据示例如下:
did <- c("1N657","1N657","1N657","1N657","1N657","1N657","1N657","1N657","1N657","1N657")
aid <- c(101,102,103,104,105,106,107,108,109,110)
temp <- c(36,38,37,39,35,37,36,34,39,38)

data <- cbind(did,aid,temp)

任何帮助将不胜感激。

最佳答案

该函数看到重复的行名,因此您需要进行处理。可能最简单的方法是使用 row.names = NULL ,这将强制进行行编号-换句话说,它将第一列视为第一维而不是行号,因此添加行号(连续的整数开始与“1”。

read.csv("S1N657.csv", header=T,fill=T, col.names=c("dam","anim","temp"), row.names=NULL)

关于r - 在R中读取具有重复行名的csv文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4066607/

10-11 04:18