Learn R Programming

PivotalR (version 0.1.18.5)

ifelse: Conditional Element Selection

Description

'ifelse' returns a value with the same shape as 'test' which is filled with elements selected from either 'yes' or 'no' depending on whether the element of 'test' is 'TRUE' or 'FALSE'.

Usage

# S4 method for db.obj
ifelse(test, yes, no)

Arguments

test

A db.obj object, which has only one column. The column can be casted into boolean values.

yes

A normal value or a db.obj object. It is the returned value when test is TRUE.

no

The returned value when test is FALSE.

Value

A '>db.obj which has the same length in-database as test.

See Also

'>db.obj

Examples

Run this code
# NOT RUN {
<!-- %% @test .port Database port number -->
<!-- %% @test .dbname Database name -->
## set up the database connection
## Assume that .port is port number and .dbname is the database name
cid <- db.connect(port = .port, dbname = .dbname, verbose = FALSE)

## create a table
x <- as.db.data.frame(abalone, conn.id = cid, verbose = FALSE)

## create a new db.obj with one-column,
## and values "small" or "big"
z <- ifelse(x$rings < 10, "small", "big")

db.disconnect(cid, verbose = FALSE)
# }

Run the code above in your browser using DataLab