0
0
R Programmingprogramming~10 mins

Arithmetic operators 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 numbers and print the result.

R Programming
result <- 5 [1] 3
print(result)
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using - instead of + will subtract instead of add.
Using * or / will multiply or divide, not add.
2fill in blank
medium

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

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

Fill 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'
Ax
Bi
Cj
Dnum
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.
5fill in blank
hard

Fill 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'
Ac
B-
C2
Dseq
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.