dplyr
has_name <- function(x) { nms <- names(x) if (is.null(nms)) { rep(FALSE, length(x)) } else { !is.na(nms) & nms != "" } }
if (this) { # do that } else if (that) { # do something else } else { # }
当需要很多if时可考虑用switch()功能
function(x, y, op) { switch(op, plus = x + y, minus = x - y, times = x * y, divide = x / y, stop("Unknown op!") ) }