Which of the following options represent R function calls?
You can recognize a valid function call by the pattern: FUNCTION_NAME().
- This is a length-one numeric vector.
- This is a symbol (i.e., the name of an object).
- Correct. This function call will list the library paths where R will install packages on your system.
- Correct. This function call would generate 100 random standard normal deviates.
- Correct. This function call would calculate the trimmed mean of
x, ignoring any missing values. - This is R’s infinite value code.
Which of the following function calls will correctly round the value 9.8765 to 2 decimal places?
- Correct: both arguments are named, so their order doesn’t matter, even though it differs from the previous answer.
- Correct: the arguments are supplied in the order
round()expects (x, thendigits), so no names are needed. - Incorrect: without argument names, R matches by position — the first value fills
xand the second fillsdigits. This call rounds2(interpreted asx) to9.8765decimal places, which is a nonsensical number of digits, not the intended calculation. - Incorrect:
round()expects an argument nameddigits, notdigit. R will not recognize this argument name. - Correct: both arguments are named, so their order doesn’t matter.
Which of the following lines of R code will produce an error when run?
- Correct: R is case-sensitive, and there is no function called
Sum()(onlysum()), so this errors. - Correct:
round()has no argument calleddigit(it’sdigits), so this errors. - Incorrect: this is valid, complete R code, so it runs without error.
- Incorrect: this is valid, complete R code (
digitsis the correct argument name), so it runs without error. - Correct: the closing parenthesis is missing, so this errors.