0
0
R Programmingprogramming~10 mins

strsplit 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 split the string 'apple,banana,cherry' by commas.

R Programming
result <- strsplit("apple,banana,cherry", [1])
Drag options to blanks, or click blank then click option'
A","
B" "
C";"
D"-"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong separator like a semicolon or space.
Not putting the separator inside quotes.
2fill in blank
medium

Complete the code to split the string 'one|two|three' by the pipe character.

R Programming
result <- strsplit("one|two|three", [1])
Drag options to blanks, or click blank then click option'
A"\\|"
B"|"
C"||"
D"\\\\|"
Attempts:
3 left
💡 Hint
Common Mistakes
Using just "|" without escaping causes unexpected splitting.
Using "\\\\|" which overescapes in R strings.
3fill in blank
hard

Fix the error in splitting the string 'a,b;c' by commas and semicolons.

R Programming
result <- strsplit("a,b;c", [1])
Drag options to blanks, or click blank then click option'
A";,"
B",;"
C"[,;]"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string with both separators without brackets.
Using separators without escaping special characters.
4fill in blank
hard

Fill both blanks to split the string 'red|green|blue' by pipe and get the first element.

R Programming
parts <- strsplit("red|green|blue", [1])
first_color <- parts[[1]][2]
Drag options to blanks, or click blank then click option'
A"\\|"
B[[1]]
C[1]
D"|"
Attempts:
3 left
💡 Hint
Common Mistakes
Not escaping the pipe character correctly.
Using single brackets [1] which returns a list, not a vector.
5fill in blank
hard

Fill all three blanks to split 'cat,dog;bird' by commas or semicolons and get the second word.

R Programming
words <- strsplit("cat,dog;bird", [1])
second_word <- words[2][3]
Drag options to blanks, or click blank then click option'
A"[,;]"
B[[1]]
C[2]
D[1]
Attempts:
3 left
💡 Hint
Common Mistakes
Using single brackets [1] instead of double brackets [[1]] to extract list element.
Not using the correct regex pattern for multiple separators.