组合具有不同列名称的2个数据帧 [英] combine 2 dataframes having different column names
本文介绍了组合具有不同列名称的2个数据帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在R中,我有两个数据帧都有不同的列名称。我想根据列号组合每个数据帧的行。
我拥有的数据框如下
> d1
X.0.52..V2 X.0.52..V4
1 ABT 700
2 AMD 9600
3 AMG 600
4 AGCO 800
> d2
X.52.96..V2 X.52.96..V4
1 COMS 162193
2 MMM 419645
3 SE 146343
4 ADCT 62609
5 TCC 6623
我想要以下数据框:
> d3
pre>
股票价值
1 ABT 700
2 AMD 9600
3 AMG 600
4 AGCO 800
5 COMS 162193
6 MMM 419645
7 SE 146343
8 ADCT 62609
9 TCC 6623
我需要使用什么代码?
解决方案如果这是简单的,我会倾向于使用:
colnames(d1)< - colnames(d2)< c(ticker,value)
rbind.data.frame(d1,d2)
In R ,I have 2 data frames both having different column name. I want to combine the rows of each data frame according to the column number. the dataframes i have is as follows
> d1 X.0.52..V2 X.0.52..V4 1 ABT 700 2 AMD 9600 3 AMG 600 4 AGCO 800 > d2 X.52.96..V2 X.52.96..V4 1 COMS 162193 2 MMM 419645 3 SE 146343 4 ADCT 62609 5 TCC 6623
I want the following dataframe:
>d3 ticker value 1 ABT 700 2 AMD 9600 3 AMG 600 4 AGCO 800 5 COMS 162193 6 MMM 419645 7 SE 146343 8 ADCT 62609 9 TCC 6623
what is the code i need to use?
解决方案If it's this simple I'd be inclined to use:
colnames(d1) <- colnames(d2) <- c("ticker", "value") rbind.data.frame(d1, d2)
这篇关于组合具有不同列名称的2个数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文