2014-03-04 54 views
0

所以我有一個96個元素的主列表。在比較R中的兩個數據幀後提取丟失的元素

masterlist <- list(c(paste0(rep(LETTERS[1:8], each=12), rep(1:12, 8)))) 

我有26個數據幀,其中,每個數據幀包含任何或所有從主列表中的元素的列表。我把這些叫做rowcol.list。在這裏,我使用下面的代碼來查看我的26個數據幀列表中的哪些數據幀與主列表不同。

rowcol.list[!(rowcol.list%in%masterlist)] 

上面的代碼返回10個數據幀,從26個數據幀的列表,如下所示:

$p01_control.txt 
[1] "A1" "A2" "A3" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" "B9" 
[21] "B10" "B11" "B12" "C1" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12" "D1" "D2" "D3" "D4" "D5" 
[41] "D6" "D7" "D8" "D9" "D10" "D11" "D12" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9" "E10" "E11" "E12" "F1" 
[61] "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10" "F11" "F12" "G1" "G2" "G3" "G4" "G5" "G6" "G7" "G8" "G9" 
[81] "G10" "G11" "G12" "H1" "H2" "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12" 

$p03_control.txt 
[1] "A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" 
[21] "B9" "B10" "B11" "B12" "C1" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12" "D1" "D2" "D3" "D4" 
[41] "D5" "D6" "D7" "D8" "D9" "D10" "D11" "D12" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9" "E10" "E11" "E12" 
[61] "F1" "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10" "F11" "F12" "G1" "G2" "G3" "G4" "G5" "G6" "G7" "G9" 
[81] "G10" "G11" "G12" "H1" "H2" "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12" 

$p04_pq.txt 
[1] "A1" "A2" "A3" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" "B9" 
[21] "B10" "B11" "B12" "C1" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12" "D1" "D2" "D3" "D4" "D5" 
[41] "D6" "D7" "D8" "D9" "D10" "D11" "D12" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9" "E10" "E11" "E12" "F1" 
[61] "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10" "F11" "F12" "G1" "G2" "G3" "G4" "G5" "G6" "G7" "G8" "G9" 
[81] "G10" "G11" "H1" "H2" "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12" 

$p07_docetaxel.txt 
[1] "A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" 
[21] "B9" "B10" "B11" "B12" "C1" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12" "D1" "D2" "D3" "D4" 
[41] "D5" "D6" "D7" "D8" "D9" "D10" "D11" "D12" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9" "E10" "E11" "E12" 
[61] "F1" "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10" "F11" "F12" "G1" "G2" "G3" "G4" "G5" "G6" "G7" "G9" 
[81] "G10" "G11" "G12" "H1" "H2" "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12" 

$p08_docetaxel_b.txt 
[1] "E10" "E11" "E12" "F1" "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10" "F11" "F12" "G1" "G2" "G3" "G4" "G5" 
[21] "G6" "G7" "G8" "G9" "G10" "G11" "G12" "H1" "H2" "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12" 

$p08_docetaxel.txt 
[1] "A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" 
[21] "B9" "B10" "B11" "B12" "C1" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12" "D1" "D2" "D3" "D4" 
[41] "D5" "D6" "D7" "D8" "D9" "D10" "D11" "D12" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" 

$p12_dactinomycin.txt 
[1] "A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" 
[21] "B9" "B10" "B11" "B12" "C1" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12" "D1" "D2" "D3" "D4" 
[41] "D5" "D6" "D7" "D8" "D9" "D10" "D11" "D12" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9" "E10" "E11" "F1" 
[61] "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10" "F11" "F12" "G1" "G2" "G3" "G4" "G5" "G6" "G7" "G8" "G9" 
[81] "G10" "G11" "G12" "H1" "H2" "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12" 

$p16_cisplatin.txt 
[1] "A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" 
[21] "B9" "B10" "B11" "B12" "C1" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12" "D1" "D2" "D3" "D4" 
[41] "D5" "D6" "D7" "D8" "D9" "D10" "D11" "D12" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9" "E10" "E11" "E12" 
[61] "F1" "F2" "F3" "F4" "F5" "F6" "F7" "F9" "F10" "F11" "F12" "G1" "G2" "G3" "G4" "G5" "G6" "G7" "G8" "G9" 
[81] "G10" "G11" "G12" "H1" "H2" "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12" 

$p18_cisplatin_b.txt 
[1] "A7" "A8" "A9" "A10" "A11" "A12" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" "B9" "B10" "B11" "B12" "C1" "C2" 
[21] "C3" "C4" "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12" "D1" "D2" "D3" "D4" "D5" "D6" "D7" "D8" "D9" "D10" 
[41] "D11" "D12" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9" "E10" "E11" "E12" "F1" "F2" "F3" "F4" "F5" "F6" 
[61] "F7" "F8" "F9" "F10" "F11" "F12" "G1" "G2" "G3" "G4" "G5" "G6" "G7" "G8" "G9" "G10" "G11" "G12" "H1" "H2" 
[81] "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12" 

$p18_cisplatin.txt 
[1] "A1" "A2" "A3" "A4" "A5" 

而不是看到,每個這些數據幀以上的有,因爲它們是不同的元素的從主列表中,我想查看數據框與主列表進行比較時沒有哪些元素。作爲一個簡短的例子,第一個數據框是不同的,$ p01_control.txt應該顯示「A4」,因爲這是缺少的。 (我只知道它缺少「A4」,因爲我瀏覽了列表並找到了缺失的那個)。

請讓我知道如何讓問題更清楚,如果它令人困惑。 謝謝!

回答

0

我會用setdiff。你可以嘗試這樣的事情:

lapply(rowcol.list,function(x) setdiff(masterlist[[1]],x)) 
相關問題