> TRUE == TRUE
[1] TRUE
> TRUE == FALSE
[1] FALSE
> TRUE != TRUE
[1] FALSE
> TRUE != FALSE
[1] TRUE
Sep 05, 2017
> TRUE == TRUE
[1] TRUE
> TRUE == FALSE
[1] FALSE
> TRUE != TRUE
[1] FALSE
> TRUE != FALSE
[1] TRUE
> "hello" == "hola"
[1] FALSE
> 5 == 2
[1] FALSE
> "hello" != "hola"
[1] TRUE
> 5 != 2
[1] TRUE
> 2 < 5
[1] TRUE
> 2 > 5
[1] FALSE
> "adios" > "goodbye" # alphabetical order!
[1] FALSE
> FALSE < TRUE # FALSE coerces to 0 and TRUE coerces to 1
[1] TRUE
> 5 >= 2
[1] TRUE
> 5 >= 5
[1] TRUE
> 5 <= 5
[1] TRUE
> boone_temp <- c(81, 72, 73, 75, 69) > boone_temp
[1] 81 72 73 75 69
> boone_temp > 72
[1] TRUE FALSE TRUE TRUE FALSE
> boone_temp >= 72
[1] TRUE TRUE TRUE TRUE FALSE
&|!&)> TRUE & TRUE # Only TRUE if both are TRUE
[1] TRUE
> FALSE & TRUE # FALSE if both not TRUE
[1] FALSE
> TRUE & FALSE
[1] FALSE
> FALSE & FALSE
[1] FALSE
&)> x <- 15 > x > 5 & x < 20 # BOTH conditions are TRUE
[1] TRUE
> x > 5 & x < 14 # ONLY one condition is TRUE
[1] FALSE
> TRUE | TRUE # TRUE if at least one is TRUE
[1] TRUE
> TRUE | FALSE # ONLY FALSE if both are FALSE
[1] TRUE
> FALSE | TRUE
[1] TRUE
> FALSE | FALSE
[1] FALSE
> y <- 11 > y < 15 | y > 15 # At least one TRUE -> TRUE
[1] TRUE
> y < 10 | y > 12 # FALSE if both FALSE
[1] FALSE
> !TRUE
[1] FALSE
> !FALSE
[1] TRUE
> x
[1] 15
> !(x <= 3)
[1] TRUE
> is.numeric(10)
[1] TRUE
> !is.numeric(10)
[1] FALSE
> is.numeric("hola")
[1] FALSE
> !is.numeric("hola")
[1] TRUE
> c(TRUE, TRUE, FALSE) & c(TRUE, FALSE, FALSE)
[1] TRUE FALSE FALSE
> c(TRUE, TRUE, FALSE) | c(TRUE, FALSE, FALSE)
[1] TRUE TRUE FALSE
> !c(TRUE, TRUE, FALSE)
[1] FALSE FALSE TRUE
> c(TRUE, TRUE, FALSE, TRUE, FALSE) & c(TRUE, FALSE, FALSE)
Warning in c(TRUE, TRUE, FALSE, TRUE, FALSE) & c(TRUE, FALSE, FALSE): longer object length is not a multiple of shorter object length
[1] TRUE FALSE FALSE TRUE FALSE
> c(TRUE, TRUE, FALSE) & c(FALSE, FALSE, FALSE)
[1] FALSE FALSE FALSE
> c(TRUE, TRUE, FALSE) && c(FALSE, FALSE, FALSE)
[1] FALSE
> c(TRUE, TRUE, FALSE) | c(FALSE, FALSE, FALSE)
[1] TRUE TRUE FALSE
> c(TRUE, TRUE, FALSE) || c(FALSE, FALSE, FALSE)
[1] TRUE
if statement (1)> if(condition){
+ expression
+ }
> x <- 5
> if(x >= 0){
+ print("x is a positive number")
+ }
[1] "x is a positive number"
if statement (2)> if(condition){
+ expression
+ }
> x <- 5
> if(x < 0){ # condition is FALSE
+ print("x is a negative number") # Print not executed
+ } # No output!
else statement (1)> if(condition){
+ expression1
+ } else {
+ expression2
+ }
else statement (2)> if(condition){
+ expression1
+ } else {
+ expression2
+ }
> x <- -5
> if(x < 0){ #Condition is TRUE
+ print("x is a negative number")
+ } else {
+ print("x is either a positive number or zero")
+ }
[1] "x is a negative number"
else statement (3)> if(condition){
+ expression1
+ } else {
+ expression2
+ }
> x <- 5
> if(x < 0){ #Condition is TRUE
+ print("x is a negative number")
+ } else {
+ print("x is either a positive number or zero")
+ }
[1] "x is either a positive number or zero"
else if statement> x <- -3
> if(x < 0) {
+ print("x is a negative number")
+ } else if(x == 0) {
+ print("x is zero")
+ } else {
+ print("x is a positive number")
+ }
[1] "x is a negative number"
> # else if TEMPLATE
> if(condition1) {
+ expression1
+ } else if(condition2) {
+ expression2
+ } else {
+ expression3
+ }else if statement (2)> x <- 0
> if(x < 0) {
+ print("x is a negative number")
+ } else if(x == 0) {
+ print("x is zero")
+ } else {
+ print("x is a positive number")
+ }
[1] "x is zero"
> # else if TEMPLATE
> if(condition1) {
+ expression1
+ } else if(condition2) {
+ expression2
+ } else {
+ expression3
+ }else statement> x <- 5
> if(x < 0) { #Cond is FALSE
+ print("x is a negative number")
+ } else if(x == 0) { #Cond is FALSE
+ print("x is zero")
+ } else {
+ print("x is a positive number")
+ }
[1] "x is a positive number"
> # TEMPLATE
> if(condition1) {
+ expression1
+ } else if(condition2) {
+ expression2
+ } else {
+ expression3
+ }if, else if, else> x <- 9
> if(x %% 2 == 0) {
+ print("divisible by 2")
+ } else if(x %% 3 == 0) {
+ print("divisible by 3")
+ } else {
+ print("not divisible by 2 nor by 3...")
+ }
[1] "divisible by 3"
> # TEMPLATE
> if(condition1) {
+ expression1
+ } else if(condition2) {
+ expression2
+ } else {
+ expression3
+ }