如何在R中有效地实现合并
NULL
coalesce <- function(...) {
apply(cbind(...), 1, function(x) {
x[which(!is.na(x))[1]]
})}a <- c(1, 2, NA, 4, NA)b <- c(NA, NA, NA, 5, 6)c <- c(7, 8, NA, 9, 10)coalesce(a,b,c)# [1] 1 2 NA 4 6
coalesce
MM们
随时随地看视频慕课网APP