R rbind错误row.names不允许复制 [英] R rbind error row.names duplicates not allowed

查看:1013
本文介绍了R rbind错误row.names不允许复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里还有其他问题涉及到同样的问题,但是我并没有意识到如何解决我的问题。所以,我有5个数据帧,我想使用rbind在一个唯一数据帧中合并行,但它返回错误:



row.names< - 。data.frame ( * tmp * ,value = value):
'row.names'不允许
另外:警告消息:
设置'row.names'时的非唯一值:'1','10','100','1000','10000','100000 ','1000000','1000001 [....]



数据帧具有相同的列,但行数不同。我以为rbind命令把第一列作为row.names。所以试图在五个数据帧中放一个顺序的ID,但是它不起作用。我试图通过row.names()指定数据帧中的顺序行名称,但也没有成功。合并命令不是我认为的选项,因为是5个数据帧,并且连续的合并将覆盖先例。我已经使用ids创建了一个新的数据框架,并尝试加入,但结果数据框架并未附加已加入的df的列。



按照df 1:

  id image power value pol class 
1 1 tsx_sm_hh 0.1834515 -7.364787 hh FR
2 2 tsx_sm_hh 0.1834515 -7.364787 hh FR
3 3 tsx_sm_hh 0.1991938 -7.007242 hh FR
4 4 tsx_sm_hh 0.1991938 -7.007242 hh FR
5 5 tsx_sm_hh 0.2079365 -6.820693 hh FR
6 6 tsx_sm_hh 0.2079365 -6.820693 hh FR
[...]
1802124 1802124 tsx_sm_hh 0.1991938 -7.007242 hh FR

另外四个df是相同的结构,除了'id'列之间没有重复的数字。 'pol'和'image'列定义为级别。
all.pol< - rbind(df1,df2,df3,df4,df5)返回重复的row.names的此错误。



任何想法?



提前感谢

解决方案

最近我有同样的错误。事实证明是我的案例中的问题是数据框的属性之一是列表。在将其转换为基本对象(例如数字)后, rbind 正常工作。



行名称是第一个变量左侧的行号。在您的示例中,它是1,2,3,...(与您的id变量相同)。



您可以使用 rownames(df)并使用 rownames(df)< - name_vector name_vector 必须具有与 df 相同的长度,其元素必须是唯一的)。


There are other issues here addressing the same question, but I don't realize how to solve my problem based on it. So, I have 5 data frames that I want to merge rows in one unique data frame using rbind, but it returns the error:

"Error in row.names<-.data.frame(*tmp*, value = value) : 'row.names' duplicated not allowed In addition: Warning message: non-unique values when setting 'row.names': ‘1’, ‘10’, ‘100’, ‘1000’, ‘10000’, ‘100000’, ‘1000000’, ‘1000001 [....]"

The data frames have the same columns but different number of rows. I thought the rbind command took the first column as row.names. So tried to put a sequential id in the five data frames but it doesn't work. I've tried to specify a sequential row names among the data frames via row.names() but with no success too. The merge command is not an option I think because are 5 data frames and successive merges will overwrite precedents. I've created a new data frame only with ids and tried to join but the resulting data frame don't append the columns of joined df.

Follows an extract of df 1:

  id    image     power     value pol class
1  1 tsx_sm_hh 0.1834515 -7.364787  hh    FR
2  2 tsx_sm_hh 0.1834515 -7.364787  hh    FR
3  3 tsx_sm_hh 0.1991938 -7.007242  hh    FR
4  4 tsx_sm_hh 0.1991938 -7.007242  hh    FR
5  5 tsx_sm_hh 0.2079365 -6.820693  hh    FR
6  6 tsx_sm_hh 0.2079365 -6.820693  hh    FR
[...]
1802124 1802124 tsx_sm_hh 0.1991938 -7.007242  hh    FR  

The four other df's are the same structure, except the 'id' columns that don't have duplicated numbers among it. 'pol' and 'image' columns are defined as levels. and all.pol <- rbind(df1,df2,df3,df4,df5) return the this error of row.names duplicated.

Any idea?

Thanks in advance

解决方案

I had the same error recently. What turned out to be the problem in my case was one of the attributes of the data frame was a list. After casting it to basic object (e.g. numeric) rbind worked just fine.

By the way row name is the "row numbers" to the left of the first variable. In your example, it is 1, 2, 3, ... (the same as your id variable).

You can see it using rownames(df) and set it using rownames(df) <- name_vector (name_vector must have the same length as df and its elements must be unique).

这篇关于R rbind错误row.names不允许复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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