Conditions

10 > 5
"aang" == "aang"
3 != 3
5 > 2 & 6 >=10
5 > 2 | 6 >=10

Exercise 1

Did you notice anything weird?

Floating point

> x <- 1.3
> y <- 2.8
>  x * 2 + 0.2 == y
[1] FALSE
> 1.3 * 2 + 0.2
[1] 2.8
>>> 1.3 * 2 + 0.2 == 2.8
False
>>> 1.3 * 2 + 0.2
2.8000000000000003

all.equal(x * 2 + 0.2, y)

Conditionals

superhero <- "Black Widow"
if (superhero == "Batman"){
  print("That is correct")
  }
print("Done")
superhero <- "Black Widow"
if (superhero == "Batman"){
  print("That is correct")
} else {
  print("Please try again")
}
print("Done)
superhero <- "Black Widow"
if (superhero == "Batman"){
  print("That is correct")
} else if (superhero == "Black Widow") {
  print("OK, you may have a point")
} else {
  print("Please try again")
}
print("Done")

Convert to function

is_best_superhero <- function(superhero){
  if (superhero == "Batman"){
	print("That is correct")
  } else if (superhero == "Black Widow") {
	print("OK, you may have a point")
  } else {
	print("Please try again")
  }
}

is_best_superhero("Hulk")

Exercise 2