Create A Function In R With If Else If Code Example


Example 1: ifelse in r


> a = c(5,7,2,9)
> b = ifelse(a %% 2 == 0,"even","odd")
# b: odd odd even odd

Example 2: if and else if in r


if ( test_expression1) {
statement1
} else if ( test_expression2) {
statement2
} else if ( test_expression3) {
statement3
} else {
statement4
}

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable