Complete the code to add two numbers and print the result.
result <- 5 [1] 3 print(result)
- instead of + will subtract instead of add.* or / will multiply or divide, not add.The + operator adds two numbers in R.
Complete the code to multiply two numbers and print the result.
result <- 7 [1] 4 print(result)
+ or - will add or subtract instead of multiply./ will divide instead of multiply.The * operator multiplies two numbers in R.
Fix the error in the code to correctly divide two numbers and print the result.
result <- 10 [1] 2 print(result)
* multiplies instead of divides.+ or - adds or subtracts instead of divides.The / operator divides the first number by the second in R.
Fill both blanks to create a named vector where each number is squared only if it is greater than 3.
[1] <- 1:5; squares <- setNames([2]^2[[1] > 3], [1][[1] > 3])
Using the same variable i for the name and the value allows squaring numbers greater than 3.
Fill all three blanks to create a vector of numbers from 1 to 5, then subtract 2 from each number and print the result.
numbers <- [1](1, 2, 3, 4, 5) result <- numbers [2] [3] print(result)
seq instead of c changes the vector creation.+ instead of - adds instead of subtracts.c() creates a vector, - subtracts, and 2 is the number to subtract.
