Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add two numbers and print the result.
R Programming
result <- 5 [1] 3 print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
- instead of + will subtract instead of add.Using
* or / will multiply or divide, not add.✗ Incorrect
The + operator adds two numbers in R.
2fill in blank
mediumComplete the code to multiply two numbers and print the result.
R Programming
result <- 7 [1] 4 print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
+ or - will add or subtract instead of multiply.Using
/ will divide instead of multiply.✗ Incorrect
The * operator multiplies two numbers in R.
3fill in blank
hardFix the error in the code to correctly divide two numbers and print the result.
R Programming
result <- 10 [1] 2 print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
* multiplies instead of divides.Using
+ or - adds or subtracts instead of divides.✗ Incorrect
The / operator divides the first number by the second in R.
4fill in blank
hardFill both blanks to create a named vector where each number is squared only if it is greater than 3.
R Programming
[1] <- 1:5; squares <- setNames([2]^2[[1] > 3], [1][[1] > 3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names for the name and the value causes errors.
Using a variable not defined in the loop causes errors.
✗ Incorrect
Using the same variable i for the name and the value allows squaring numbers greater than 3.
5fill in blank
hardFill all three blanks to create a vector of numbers from 1 to 5, then subtract 2 from each number and print the result.
R Programming
numbers <- [1](1, 2, 3, 4, 5) result <- numbers [2] [3] print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
seq instead of c changes the vector creation.Using
+ instead of - adds instead of subtracts.Using a wrong number instead of 2 changes the result.
✗ Incorrect
c() creates a vector, - subtracts, and 2 is the number to subtract.