# NOT RUN {
Coalesce(c(NA, NA, NA, 5, 3))
Coalesce(c(NA, NULL, "a"))
Coalesce(NULL, 5, 3)
d.frm <- data.frame(matrix(c(
1, 2, NA, 4,
NA, NA, 3, 1,
NaN, 2, 3, 1,
NA, Inf, 1, 1), nrow=4, byrow=TRUE)
)
Coalesce(d.frm)
Coalesce(as.matrix(d.frm))
Coalesce(d.frm$X1, d.frm$X2, d.frm$X3, d.frm$X4)
Coalesce(d.frm$X1, d.frm$X2, d.frm$X3, d.frm$X4, method="is.finite")
Coalesce(list(d.frm[,1], d.frm[,2]))
# returns the first finite element
Coalesce(d.frm, method="is.finite")
# with characters (take care, factors won't work!)
# is.finite does not make sense here...
d.frm <- data.frame(matrix(c(
"a", "b", NA, "4",
NA, NA, "g", "m",
NA_character_,"hfdg", "rr", "m",
NA, Inf, 1, 1), nrow=4, byrow=TRUE)
, stringsAsFactors = FALSE)
Coalesce(d.frm$X1, d.frm$X2, d.frm$X3, d.frm$X4)
Coalesce(d.frm)
Coalesce(as.list(d.frm))
# }
Run the code above in your browser using DataLab