如何用特定符号合并R中的两列?
我在 R 中读取了一个表,如下所示:
column1 column2
A B
用于将两列匹配在一起的命令是什么?
Column 3
A_B
I have a table read in R as follows:
column1 column2
A B
What is the command to be used to match two columns together as follows?
Column 3
A_B
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有点不确定你所说的“合并”是什么意思,但这就是你的意思吗?
或者等效地,正如@daroczig 指出的:
I'm a bit unsure what you mean by "merge", but is this what you mean?
Or equivalently, as @daroczig points out:
我个人最喜欢的是使用
unite
intidyr
:结果
旁注 就
我个人而言,我发现 unite 的
remove = TRUE / FALSE
功能非常有用。此外,tidyr
很好地实现了dplyr
工作流程,并且与单独
,以防您改变对合并列的想法。同样,如果NA
是问题所在,则在工作流程中引入na.omit
将使您能够在创建所需列之前方便地删除不需要的行。My personal favourite involves making use of the
unite
intidyr
:Results
Side notes
Personally, I find the
remove = TRUE / FALSE
functionality of unite very useful. In additiontidyr
firs thedplyr
workflow very well and plays well withseparate
in case you change your mind about the columns being merged. On the same lines, ifNA
s are the problem introducingna.omit
to your workflow would enable you to conveniently drop the undesirable rows before creating the desired column.