简体   繁体   English

在R中,如何合并data.frame中的两列

[英]In R, how can I combine two columns within a data.frame

I'm working with some data that looks like this: 我正在处理一些看起来像这样的数据:

AB 123 4 5 3 2 1
AB 234 4 2 7 4 3 
...

The row id is actually the combination of the first two columns, so I would like to be able to reference row AB123 or AB234. 行ID实际上是前两列的组合,因此我希望能够引用行AB123或AB234。 However, since they are in two columns, I figured the easiest way to do this would be to merge columns 1 and 2 somehow and then convert it to a table with column 1 specified as the row names. 但是,由于它们位于两列中,因此我想到了最简单的方法是以某种方式合并第1列和第2列,然后将其转换为指定为第1列作为行名的表。 Does anyone know how I can do this? 有人知道我该怎么做吗? Is there an easier way? 有更容易的方法吗? Thanks. 谢谢。

row.names(df)<-paste(df[,1],df[,2],sep="")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM