1. Logic

a <- 1
b <- 2

a == 1
## [1] TRUE
a == b
## [1] FALSE
a < b
## [1] TRUE
a > b
## [1] FALSE
a <= b
## [1] TRUE
a >= b
## [1] FALSE
a != b
## [1] TRUE

1.1 IF statements

# 1
myNumber <- 0
if(myNumber==1){myNumber <- myNumber + 1}

myNumber
## [1] 0
# 2
myNumber <- 1
if(myNumber==1){myNumber <- myNumber + 1}

myNumber
## [1] 2
# 3
myNumber <- 0
if(myNumber==1) {myNumber <- myNumber + 1} else {myNumber <- myNumber + 2}
myNumber
## [1] 2

1.1.1 Nested IF statements

# 1
CurrentLocation <- "outside"
Weather <- "raining"
if(CurrentLocation=="outside"){
  if(Weather=="raining"){
    Umbrella <- TRUE
  }else{
    Umbrella <- FALSE
  }
}else{
  Umbrella <- FALSE
}
Umbrella
## [1] TRUE
# 2
CurrentLocation <- "inside"
Weather <- "raining"
if(CurrentLocation=="outside"){
  if(Weather=="raining"){
    Umbrella <- TRUE
  }else{
    Umbrella <- FALSE
  }
}else{
  Umbrella <- FALSE
}
Umbrella
## [1] FALSE

1.1.2 AND

# 1
CurrentLocation <- "outside"
Weather <- "raining"
if(CurrentLocation=="outside" && Weather=="raining"){
  Umbrella<-TRUE
}else{
  Umbrella<-FALSE
}
Umbrella
## [1] TRUE
# 2
CurrentLocation<-"outside"
Weather<-"raining"
Umbrella<-FALSE
if(CurrentLocation=="outside" && Weather=="raining"){
  Umbrella<-TRUE
}
Umbrella
## [1] TRUE

1.1.3 OR

CurrentLocation <- "inside"
Weather <- "raining"
Umbrella <- FALSE
if(CurrentLocation=="outside" || Weather=="raining"){
  Umbrella <- TRUE
}
Umbrella
## [1] TRUE