Table of Contents

R - If / ifElse

About

See

?Control

If you want a:

Type

if

With one value

Syntax

if(cond) expr
if(cond) cons.expr  else  alt.expr

where:

Example

if(1>2) {
    print("1>2")
} else if(FALSE) {
    print (FALSE)
} else {
    print("2>1")
}
x = if(4 > 3) { 1 } else { 0 } 

ifelse

If else takes vectors as input and return vector on output

df$TOTAL_TIME_SEC_CAPPED <-  ifelse(df$TOTAL_TIME_SEC > 200, 200, df$TOTAL_TIME_SEC)