Complete the code to print the number 5.
print([1])
The print() function outputs the value inside the parentheses. Using 5 prints the number 5.
Complete the code to assign the value 10 to variable x.
[1] <- 10
In R, the assignment operator <- assigns the value on the right to the variable on the left. Here, x is the variable name.
Fix the error in the code to calculate the sum of 3 and 4.
result <- 3 [1] 4
The plus sign + adds two numbers. Using it here sums 3 and 4 correctly.
Fill both blanks to create a vector of numbers from 1 to 5.
numbers <- c([1]:[2])
The colon operator : creates a sequence from the first number to the second. Here, 1:5 makes numbers 1 through 5.
Fill all three blanks to create a named vector with scores greater than 50.
scores <- c(Alice=60, Bob=45, Carol=75) passed <- scores[scores [1] [2]] result <- [3](names(passed))
mean() instead of sort() for names.This code selects scores greater than 50 using > and 50. Then it gets the names of those who passed and sorts them with sort().