Learn R Programming

SBCK (version 1.0.0)

where: where function

Description

This function return a vector / matrix / array of the same shape than cond / x / y such that if(cond) values are x, and else y.

Usage

where(cond,x,y)

Value

z [vector/matrix/array].

Arguments

cond

[vector/matrix/array] Boolean values

x

[vector/matrix/array] Values if cond is TRUE

y

[vector/matrix/array] Values if cond is FALSE

Examples

Run this code
x = base::seq( -2 , 2 , length = 100 )
y = where( x < 1 , x , exp(x) ) ## y = x if x < 1, else exp(x)

Run the code above in your browser using DataLab