Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to add two vectors element-wise.
R Programming
result <- c(1, 2, 3) [1] c(4, 5, 6)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
- instead of + causes subtraction.✗ Incorrect
In R, the + operator adds vectors element-wise.
2fill in blank
mediumComplete the code to multiply two vectors element-wise.
R Programming
result <- c(2, 4, 6) [1] c(3, 5, 7)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
+ adds instead of multiplies.✗ Incorrect
The * operator multiplies vectors element-wise in R.
3fill in blank
hardFix the error in the code to subtract vectors element-wise.
R Programming
result <- c(5, 7, 9) [1] c(1, 2, 3)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
+ adds instead of subtracts.✗ Incorrect
The - operator subtracts vectors element-wise in R.
4fill in blank
hardFill both blanks to divide two vectors element-wise and assign to result.
R Programming
result <- c(10, 20, 30) [1] c(2, 4, 5) [2] 2
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
+ or - instead of division or multiplication.✗ Incorrect
The / operator divides vectors element-wise. The * operator multiplies the result by 2.
5fill in blank
hardFill all three blanks to create a vector of squared differences between two vectors.
R Programming
result <- (c(3, 6, 9) [1] c(1, 2, 3)) [2] [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
+ instead of subtraction.Using
* instead of exponentiation.✗ Incorrect
Subtract vectors element-wise with -, then raise to the power ^ of 2 to square the differences.