如何将R中的两列与特定符号合并? [英] How to merge two columns in R with a specific symbol?
本文介绍了如何将R中的两列与特定符号合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个在R中读取的表,如下所示:
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
推荐答案
我有点不确定合并"的意思,但这是您的意思吗?
I'm a bit unsure what you mean by "merge", but is this what you mean?
> DF = data.frame(A = LETTERS[1:10], B = LETTERS[11:20])
> DF$C = paste(DF$A, DF$B, sep="_")
> head(DF)
A B C
1 A K A_K
2 B L B_L
3 C M C_M
4 D N D_N
或等效地,如@daroczig指出的:
Or equivalently, as @daroczig points out:
within(DF, C <- paste(A, B, sep='_'))
这篇关于如何将R中的两列与特定符号合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文