Knowledge Quiz: Basic Commands

Which of the following commands represents the recommended way to assign the value 7 to the object y?

Although there are three valid assignment operators: <-, ->, =, only the left-facing arrow is recommended by most style guides.

  • That’s the correct assignment operator, but this command assigns the wrong value.
  • This is a logical comparison. We’re checking if the value of y is less than 7.
  • While = is a legal assignment operator, using an equals sign for assignment is not recommended style.
  • Correct
  • This isn’t legal R code. This command attempts to assign the value y to the variable 7, but variable names can’t begin with numbers.

What value will the following R code produce?

10 - 2 * 3

By applying the appropriate order of operations (parentheses before multiplication/division before addition/subtraction), we get 4.

Which of the following expressions will return TRUE?

  • FALSE: 7 is equal to 7, but 7 is not strictly greater than 7 (both conditions must be true)
  • FALSE: Trivially
  • TRUE: “alice” is not equal to “bob”, but “alice is equal to”alice” (at least one condition must be true)
  • FALSE: “alice” is equal to “alice”, but “alice” is not equal to “bob” (both conditions must be true)
  • FALSE: “foo” is not equal to “bar”

What will the following R code print when you run it?

# 4 * 2
# 4 - 2
4 / 2
4^2
  • A # character simply marks the rest of the line as a comment. These comments would not cause an error.
  • The lines starting with # are comment and are never evaluated, so R only prints the results of the last two lines.
  • Commented lines are not evaluated as R code, so no output would be printed for the first two lines.
  • Both the third and fourth lines are evaluated, so we would see two printed values.
  • Commented lines are not evaluated as R code, so no 0 would be printed.
Note
  • Click the check-mark button to check your answer.
  • Click the question-mark button to see an explanation of the solution.
Back to top