0
0
R Programmingprogramming~10 mins

Special operators (%in%, %*%) 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 check if 3 is in the vector.

R Programming
3 [1] c(1, 2, 3, 4, 5)
Drag options to blanks, or click blank then click option'
A%in%
B%*%
C%/%
D%%
Attempts:
3 left
💡 Hint
Common Mistakes
Using %*% which is for matrix multiplication.
Using %% which is for modulo operation.
2fill in blank
medium

Complete the code to multiply two matrices A and B.

R Programming
result <- A [1] B
Drag options to blanks, or click blank then click option'
A%in%
B%%
C%*%
D%/%
Attempts:
3 left
💡 Hint
Common Mistakes
Using %in% which checks membership, not multiplication.
Using %% which is modulo, not multiplication.
3fill in blank
hard

Fix the error in the code to check if 'apple' is in the fruits vector.

R Programming
'apple' [1] fruits
Drag options to blanks, or click blank then click option'
A%*%
Bis.in
Cin
D%in%
Attempts:
3 left
💡 Hint
Common Mistakes
Using %*% which is matrix multiplication.
Using 'in' without percent signs which is not valid syntax.
4fill in blank
hard

Fill both blanks to create a named vector with lengths of words longer than 3 characters.

R Programming
lengths <- c([1] = [2] for word in words if nchar(word) > 3)
Drag options to blanks, or click blank then click option'
Aword
Bnchar(word)
Clength(word)
Dcount(word)
Attempts:
3 left
💡 Hint
Common Mistakes
Using length(word) which returns 1 for strings.
Using count(word) which is not a base R function.
5fill in blank
hard

Fill all three blanks to create a named vector of word lengths for words longer than 4 characters.

R Programming
word_lengths <- c([1] = [2] for word in words if nchar(word) [3] 4)
Drag options to blanks, or click blank then click option'
Aword
Bnchar(word)
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' in the condition.
Using length(word) instead of nchar(word).