--1-Conditionals and Control Flow

#1-Relational Operators

Relational operators video

#2-Equality

  • In the editor on the right, write R code to see if TRUE equals FALSE.

  • Likewise, check if -6 * 14 is not equal to 17 - 101.

  • Next up: comparison of character strings. Ask R whether the strings "useR" and "user" are equal.

  • Finally, find out what happens if you compare logicals to numerics: are TRUE and 1 equal?

# Comparison of logicals
TRUE==FALSE

# Comparison of numerics
-6*14 != 17-101

# Comparison of character strings
'useR'=='user'

# Compare a logical with a numeric
TRUE==1

#3-Greater and less than

Write R expressions to check whether:

  • -6 * 5 + 2 is greater than or equal to -10 + 1.

  • "raining" is less than or equal to "raining dogs".

  • TRUE is greater than FALSE.

#4-Compare vectors

Using relational operators, find a logical answer, i.e. TRUE or FALSE, for the following questions: On which days did the number of LinkedIn profile views exceed 15? When was your LinkedIn profile viewed only 5 times or fewer? When was your LinkedIn profile visited more often than your Facebook profile?

#5-Compare matrices

Using the relational operators you've learned so far, try to discover the following: When were the views exactly equal to 13? Use the views matrix to return a logical matrix. For which days were the number of views less than or equal to 14? Again, have R return a logical matrix.

#6-Logical Operators

Logical operators video

#7-& and | (AND & OR)

#8-& and | (AND & OR) (2)

#9-Reverse the result: !

#10-Blend it all together

#11-Conditional Statements

How to use conditional statements in r

#12-The if statement

#13-Add an else

#14-Customize further: else if

#15-Else if (2)

#15-Else if (3)

Last updated