Learn R Programming

inops (version 0.0.1)

comparison_replace: Replacing Values by Comparison

Description

Operators for replacing values using the standard comparison operators.

Usage

x >= y <- value

x > y <- value

x <= y="" <-="" value<="" p="">

x < y <- value

x == y <- value

x != y <- value

Arguments

x

first element of the operation.

y

second element of the operation.

value

replacement value.

Value

x with values for which the comparisons evaluate to TRUE replaced with value.

Details

Thanks to these operators :

  • x == y <- value is equivalent to x[x == y] <- value

  • x != y <- value is equivalent to x[x != y] <- value

  • x <= y <- value is equivalent to x[x <= y] <- value

  • x >= y <- value is equivalent to x[x >= y] <- value

  • x < y <- value is equivalent to x[x < y] <- value

  • x > y <- value is equivalent to x[x > y] <- value

See Also

`==`

Examples

Run this code
# NOT RUN {
ages <- c(130, 10, 1996, 21, 39, 74, -2, 0)

ages == 1996 <- as.numeric(format(Sys.Date(), "%Y")) - 1986
ages

ages > 100 <- NA
ages

ages <= 0 <- NA
ages

# }

Run the code above in your browser using DataLab