不允许重复的"row.names"错误 [英] duplicate 'row.names' are not allowed error
问题描述
我正在尝试加载具有以下14列的csv文件:
I am trying to load a csv file that has 14 columns like this:
StartDate, var1, var2, var3, ..., var14
当我发出此命令时:
systems <- read.table("http://getfile.pl?test.csv", header = TRUE, sep = ",")
我收到一条错误消息.
重复的行名是不允许的
duplicate row.names are not allowed
在我看来,第一列名称是造成此问题的原因.当我手动下载文件并从文件中删除StartDate
名称时,R成功读取文件并将第一列名称替换为X
.有人可以告诉我怎么回事吗?该文件是一个(用逗号分隔的)csv文件.
It seems to me that the first column name is causing the issue. When I manually download the file and remove the StartDate
name from the file, R successfully reads the file and replaces the first column name with X
. Can someone tell me what is going on? The file is a (comma separated) csv file.
推荐答案
然后告诉read.table not 使用row.names
:
Then tell read.table not to use row.names
:
systems <- read.table("http://getfile.pl?test.csv",
header=TRUE, sep=",", row.names=NULL)
现在您的行将简单地编号.
and now your rows will simply be numbered.
还要查看read.csv
,它是read.table
的包装,该包装已经设置了sep=','
和header=TRUE
参数,以便您的调用简化为
Also look at read.csv
which is a wrapper for read.table
which already sets the sep=','
and header=TRUE
arguments so that your call simplifies to
systems <- read.csv("http://getfile.pl?test.csv", row.names=NULL)
这篇关于不允许重复的"row.names"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!