1
Answer to question about error handling with lapply的索引總是返回NA
或NULL
當一個元件出現故障時,即錯誤與lapply處理 - 輸出失敗元素
myfun <- function(s) {
tryCatch(doSomething(s), error = function(e) { return(NULL) }
}
然而,這是不夠的,因爲一般可以doSomething(s)
返回NULL
或NA
本身。因此,理想情況下,我想要myfun
這樣寫,以便lapply(mylist, myfun)
後我可以以某種方式獲取失敗元素的所有索引。這個怎麼做?