我有一個包含26個數據幀的列表。我使用下面的代碼來創建一個向量。有沒有一種方法可以使用for循環在所有26個數據幀上應用相同的唯一函數,並在每個數據幀中有一個包含矢量的26個數據幀的新列表?每個數據幀將根據該數據幀創建不同的矢量。使用for循環在R中創建數據幀列表
(unique(paste(list[[1]]$row, list[[1]]$col, sep=""))
> (unique(paste(list[[1]]$row, list[[1]]$col, sep="")))
[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"
所以結果我想是一樣的東西......
[[1]]
[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"
[[2]]
[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"
[[3]]
[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"
etc etc until [[26]]
澄清
每個數據幀中包含的任何或全部以下列表中包含的元素(以下列表有96個元素):
list(c(paste0(rep(LETTERS[1:8], each=12), rep(1:12, 8))))
所以我需要的東西會通過我的26個數據幀的列表,並告訴我每個數據幀包含的元素。因爲某些數據框可能沒有全部96個元素,所以我在我的結果示例中顯示[[3]]只有像.. 40個元素。希望現在更清楚..
使用'lapply'。它專爲這些任務而設計。 – Roland
@羅蘭這樣的事情? lapply(list,function(x)unique(paste(list [[i]] $ row,list [[i]] $ col,sep =「」)))它給了我現在列表的數據框,它的返回與原始列表的每個數據幀都不相符。 – hj14
差不多。 'lapply(list,function(x)unique(paste0(x $ row,x $ col)))'' – Roland