我有IntegerList中的位置索引列表,我打算按給定的閾值對它們進行過濾,並且效果很好。不過,我想爲每個IntegerList提取一個特定的過濾集以供進一步使用。我知道myList是嵌套列表,並且數據是基於真實數據集非常模擬的。有什麼方法可以輕鬆而優雅地檢索想要的IntegerList嗎?我怎樣才能使這種提取發生?任何方式從嵌套列表中更優雅地提取命名的IntegerList?
要運行迷你例如,需要以下庫:
library(IRanges)
library(S4Vectors)
迷你例如:
myList <- list(f1=IntegerList(1,2,3,4,1,1,1,integer(0),1,2,4),
f2=IntegerList(1,5,integer(0),integer(0),2,3,4,6,1,5,6),
f3=IntegerList(1,4,6,7,2,3,3,7,2,5,7))
len <- Reduce('+', lapply(myList, lengths))
keepMe <- len >= length(myList)
我打算將它們過濾如下:
res.filt <- lapply(myList, function(elm) {
ans <- list(keep=elm[keepMe], droped=elm[!keepMe])
ans
})
我粗略的輸出:
Keep.list <- list(f1.kp=res.filt$f1$keep, f2.kp=res.filt$f2$keep, f3.kp=res.filt$f3$keep)
Drop.list <- list(f1.dp=res.filt$f1$droped, f2.dp=res.filt$f2$droped, f3.dp=res.filt$f3$droped)
基於我粗略的輸出,我怎樣才能得到更優雅的輸出?任何有效的方式來實現我的輸出?任何人都可以指出我該怎麼做?或者有什麼建議如何獲得我的預期產出?在此先感謝
你能不能解釋清楚你的意思是什麼「更優雅」? –
我只是不明白,如果你正在談論結果,代碼或輸出的格式 –
感謝您的快速回復。我得到的解決方案:) –