R - rbind 问题 ->具有相同名称和格式的重复列
最近,我在 RStudio 中使用 rbind 将数据表添加到另一个表时遇到了一个问题。假设两个数据表有两列名称和格式完全相同(我已使用 str() 检查过这一点)。 但是当我想绑定它们时(代码 table3<-rbind(table1, table2,fill=T)),它会复制这些列,以便在生成的 table3 中有两列具有完全相同的名称(第一个列的条目为来自 table1 的所有行和 table2 的所有行的第二行)或者它的列名只有一次,但来自 table2 的所有行条目都是 NA。 两者都非常烦人,而且也是一个新问题,因为我之前使用了完全相同的代码并且它运行得很好。我使用的RVersion是R.4.1.1。我是否忽略了什么?或者这个版本可能存在一些错误?
非常感谢您的帮助。
recently I was confronted with a problem in RStudio when using rbind to add a data table to another. Assume the two data tables have two columns with exactly the same name and format (I have checked this with str()).
But when I want to bind them (Code table3<-rbind(table1, table2,fill=T)) either it duplicates the columns so that in the resulting table3 there a two columns with exactly the same name (the first one has entries for all rows coming from table1 and the second one for all rows of table2) or it has the name of the column only once but all the entries of rows coming from table2 are NA.
Both is very annoying, and also a new problem, because I used exactly the same code earlier and it was working perfectly well. The RVersion I'm using is R.4.1.1. Am I overlooking something? Or might there be some bug in this version?
Thanks very much for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 merge(),例如:
try to use merge(), e.g.:
检查以确保两者的编码相同。
可重现的例子。
对列名称进行编码
一个修复?复制编码:
对内容进行编码
我认为这不是问题,因为它会产生不同的(尽管相似)错误。
类似的修复:
请注意未来的自己:我假设 dput 的输出完全明确,但发现了它的缺陷:
Check to ensure that the encoding is the same on both.
Reproducible examples.
Encoding on the column names
One fix? Copy the encoding:
Encoding on the contents
I don't think this is the problem, as it is producing a different (though similar) error.
Similar fix:
Note to future self: my assumption that the output from
dput
is perfectly unambiguous has found its flaw: