不允许重复的“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 = ",")
我收到一条错误消息.
不允许重复行名称
在我看来,第一列名称是导致问题的原因.当我手动下载文件并从文件中删除 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不要使用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屋!