2015-11-18 19 views
1

我試圖合併兩個xdf文件後,子集基於一個變量重複id的長表。革命/ rxMerge和行重複

假設我有兩列:ID和類型

我子集基礎上的發言權type = 'type1'原XDF表,並獲得第一XDF文件 我子集基礎上的發言權type = 'type2'原XDF表,並獲得第二XDF文件

第一XDF文件看起來像 (有不同的ID的相當多的數量,但是我顯示一個ID在下面的示例)

id type1 
__ ____ 
1 5 

釷E二次XDF文件看起來像 (有不同ID的相當多的數字,但我在下面的例子演示了一個ID)

id type2 
__ ____ 
1 3 

然後,我合併兩個XDF文件到另一個XDF文件

rxMerge(file1, file2, outFile = final, autoSort = FALSE, matchVars = 'id', type = 'full', overwrite = TRUE) 

我得到兩個記錄ID = 1爲

id type1 type2 
__ ____ ______ 
1 5 NA 

1 NA 3 

我期待

id type1 type2 
__ ____ ______ 
1 5 3 

我在做什麼錯?

回答

0

嗯......你的例子作爲我給出的的作品,RRE 7.4.1:

# Example data 
x <- data.frame(id = 1, type1 = 5) 
y <- data.frame(id = 1, type2 = 3) 

# Creating XDFs for the example data 
file1 <- tempfile(fileext = ".xdf") 
rxImport(inData = x, outFile = file1) 

file2 <- tempfile(fileext = ".xdf") 
rxImport(inData = y, outFile = file2) 

# Merging into a third XDF 
final <- tempfile(fileext = ".xdf") 

rxMerge(inData1 = file1, 
     inData2 = file2, 
     outFile = final, 
     autoSort = FALSE, 
     matchVars = 'id', 
     type = 'full', 
     overwrite = TRUE) 

# Check the output 
rxDataStep(final) 

因此很難知道可能什麼。當你設置autoSort = TRUE會發生什麼?你正在運行什麼版本的RRE? (您可以通過加載RevoScaleR並運行sessionInfo()獲取版本號)