加入两个具有不同结构但内容相同的data.tables / data.frames

时间:2013-04-17 11:48:38

标签: r dataframe data.table

我有两个data.table由不同的操作创建,但值是相同的。但是,它们具有不同的结构,如输出所示:

> str(resultstabledata)
Classes ‘data.table’ and 'data.frame':  234 obs. of  7 variables:
 $ pT      : Factor w/ 4 levels "Insignificant",..: 4 4 4 4 4 4 1 1 3 3 ...
 $ shape   : Factor w/ 2 levels "Base","Comparison": 1 1 1 1 1 1 1 1 1 1 ...
 $ resid   : chr  "minzer" "minzer" "minzer" "minzer" ...
 $ asset   : Factor w/ 3 levels "crude","gold",..: 1 1 2 2 3 3 3 3 3 3 ...
 $ base    : Factor w/ 3 levels "mlp","elman",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ compared: Factor w/ 2 levels "arfima.roll",..: 1 2 1 2 1 2 1 2 1 2 ...
 $ N       : int  409 317 194 353 206 178 317 333 47 46 ...
 - attr(*, ".internal.selfref")=<externalptr> 
> str(a)
'data.frame':   7 obs. of  7 variables:
 $ pT      : Factor w/ 4 levels "Insignificant",..: 1 2 2 3 3 4 4
 $ shape   : Factor w/ 1 level "Comparison": 1 1 1 1 1 1 1
 $ resid   : Factor w/ 2 levels "minzer","diff": 1 1 2 1 2 1 2
 $ asset   : Factor w/ 1 level "crude": 1 1 1 1 1 1 1
 $ base    : Factor w/ 1 level "mlp": 1 1 1 1 1 1 1
 $ compared: Factor w/ 1 level "lame": 1 1 1 1 1 1 1
 $ N       : num  0 0 0 0 0 0 0 

是否有一种简单的方法如何对它们进行rbind而不是重新解释这些因素,因为“字幕”这个级别是按照构造正确的?

澄清我的要求: 我期待这样的行为。我有两个data.tables / frames ab。两者都有变量x factor,但在a 1-&gt;“bla”,2-&gt;“ble”和b 1-&gt;“ble ”,2→‘BLA’。我们假设结构a$xbla bla ble bleb$xble ble bla bla。通过执行merged <- rbind(a,b),我希望merged$xbla bla ble ble ble ble bla bla,但我遇到merged$xbla bla ble ble bla bla ble ble

感谢您的建议。

0 个答案:

没有答案