R/ifelse.R

## ----------------------------------------------------------------------
## ifelse
## ----------------------------------------------------------------------

setGeneric("ifelse")

setMethod("ifelse",
    signature(test = "db.obj"),
    function (test, yes, no)
    {
        test <- test[,]
        if (length(names(test)) != 1)
            stop(deparse(substitute(test)), " must have only one column",
                 " and the column type can be casted into boolean!")
        x <- test
        x$res <- no
        x$res[as.logical(test),] <- yes
        x$res
    }
)

Try the PivotalR package in your browser

Any scripts or data that you put into this service are public.

PivotalR documentation built on March 13, 2021, 1:06 a.m.