在 R 中读取具有重复行名称的 csv 文件 [英] reading a csv file with repeated row names in R

查看:174
本文介绍了在 R 中读取具有重复行名称的 csv 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取具有重复行名称的 csv 文件,但无法读取.我收到的错误消息是 Error in read.table(file = file, header = header, sep = sep, quote = quote, : 不允许重复的 'row.names'.

I am trying to read a csv file with repeated row names but could not. The error message I am getting is 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"开头的连续整数.

the function is seeing duplicate row names, so you need to deal with that. Probably the easiest way is with row.names=NULL, which will force row numbering--in other words, it treats your first column as the first dimension and not as the row numbers, and so adds row numbers (consecutive integers starting with "1".

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

这篇关于在 R 中读取具有重复行名称的 csv 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆