0
0
R Programmingprogramming~10 mins

Vector arithmetic (element-wise) in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A*
B-
C/
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using - instead of + causes subtraction.
2fill in blank
medium

Complete 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'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using + adds instead of multiplies.
3fill in blank
hard

Fix 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'
A*
B-
C+
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using + adds instead of subtracts.
4fill in blank
hard

Fill 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'
A/
B*
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using + or - instead of division or multiplication.
5fill in blank
hard

Fill 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'
A-
B+
C2
D^
Attempts:
3 left
💡 Hint
Common Mistakes
Using + instead of subtraction.
Using * instead of exponentiation.