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.
- Correct
- This isn’t legal R code. This command attempts to assign the value
yto the variable7, but variable names can’t begin with numbers. - This command adds the value of
yto the value of7and prints the result. - That’s the correct assignment operator, but this command assigns the wrong value.
- This is technically valid assignment, but putting the variable on the right-hand side of the assignment operator is not recommended style.
What value will the following R code produce?
(7 - 3) * 4 - 2
By applying the appropriate order of operations, we get 14.
What value will the following R code produce?
2 + 3 * 4
By applying the appropriate order of operations (parentheses before multiplication/division before addition/subtraction), we get 14.
Which of the following expressions will return TRUE?
- FALSE: “alice” is not equal to “bob”, and “alice” is equal to “alice”
- TRUE: “alice” is not equal to “bob”, but “alice is equal to”alice”
- FALSE: “foo” is not equal to “bar”
- FALSE: “alice” is not equal to “bob”
- FALSE: 7 is equal to 7, but 7 is not strictly greater than 7
- FALSE: Trivially
What will the following R code print when you run it?
5 + 5
# 5 - 5
5 * 5
- Incorrect: a
#simply marks the rest of the line as a comment; it doesn’t cause an error. - Incorrect: the commented line is never evaluated by R, so
0is never printed. - Incorrect: the third line (
5 * 5) is still evaluated and printed. - Incorrect: the first line (
5 + 5) is still evaluated and printed. - Correct: the line starting with
#is a comment and is never evaluated, so R only prints the results of the first and third lines.