0
0
R Programmingprogramming~20 mins

strsplit in R Programming - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Strsplit Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of strsplit with multiple delimiters
What is the output of the following R code?
R Programming
text <- "apple,banana;cherry orange"
result <- strsplit(text, split = ",|;| ")
print(result)
A
[[1]]
[1] "apple" "banana" "cherry orange"
B
[[1]]
[1] "apple,banana;cherry orange"
C
[[1]]
[1] "apple" "banana;cherry" "orange"
D
[[1]]
[1] "apple" "banana" "cherry" "orange"
Attempts:
2 left
💡 Hint
The split argument can use regular expressions to split by multiple characters.
Predict Output
intermediate
2:00remaining
Result of strsplit with fixed = TRUE
What is the output of this R code?
R Programming
text <- "one.two.three"
result <- strsplit(text, split = ".", fixed = TRUE)
print(result)
A
[[1]]
[1] "one" "two" "three"
B
[[1]]
[1] "one.two.three"
C
[[1]]
[1] "one" "two.three"
D
[[1]]
[1] "one.two" "three"
Attempts:
2 left
💡 Hint
fixed = TRUE treats the split string literally, not as a regular expression.
🔧 Debug
advanced
2:00remaining
Identify the error in strsplit usage
What error does this R code produce?
R Programming
text <- "a,b,c"
result <- strsplit(text, split = c(",", ";"))
print(result)
AError in strsplit: unused argument (split = c(",", ";"))
BError in strsplit: 'split' must be a single string
C
[[1]]
[1] "a" "b" "c"
DNULL
Attempts:
2 left
💡 Hint
The split argument must be a single string, not a vector.
🧠 Conceptual
advanced
1:30remaining
Understanding strsplit output structure
What is the type and structure of the value returned by strsplit in R?
AA list where each element is a character vector of split parts
BA character vector of split parts
CA data frame with columns for each split part
DA matrix of characters with rows as split parts
Attempts:
2 left
💡 Hint
strsplit always returns a list, even if input is a single string.
Predict Output
expert
1:30remaining
Count of elements after splitting multiple strings
What is the length of the vector inside the first element of the list returned by this code?
R Programming
texts <- c("red,green,blue", "circle,square")
result <- strsplit(texts, split = ",")
length(result[[1]])
A1
B2
C3
DError: subscript out of bounds
Attempts:
2 left
💡 Hint
The first element corresponds to splitting the first string.