0
0
R Programmingprogramming~5 mins

strsplit in R Programming - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the strsplit function do in R?

strsplit splits a string into pieces based on a separator you choose. It returns a list of character vectors.

Click to reveal answer
beginner
How do you split the string "apple,banana,orange" by commas using strsplit?

Use strsplit("apple,banana,orange", ","). This splits the string at each comma.

Click to reveal answer
beginner
What type of object does strsplit return?

strsplit returns a list, where each element is a character vector of the split parts of the original string.

Click to reveal answer
intermediate
How can you split multiple strings at once using strsplit?

Pass a vector of strings to strsplit. It returns a list with one element per string, each containing the split parts.

Click to reveal answer
intermediate
What happens if the separator is not found in the string when using strsplit?

The entire string is returned as a single element in a character vector inside the list.

Click to reveal answer
What is the output type of strsplit("a,b,c", ",")?
AA numeric vector
BA character vector
CA list containing a character vector
DA data frame
Which argument in strsplit specifies where to split the string?
Asplit
Bsep
Cdelimiter
Dseparator
What will strsplit("hello world", " ") return?
A"hello world"
B[["hello", "world"]]
C["hello world"]
D[["hello world"]]
If you run strsplit(c("a,b", "c,d"), ","), what is the length of the returned list?
A0
B1
C4
D2
What happens if the split character is not found in the string?
AThe whole string is returned as one element
BAn error occurs
CAn empty vector is returned
DThe string is removed
Explain how to use strsplit to split a string by a comma and what the output looks like.
Think about how you break a sentence into words using spaces.
You got /4 concepts.
    Describe what happens when you use strsplit on a vector of multiple strings.
    Imagine splitting several sentences at once.
    You got /4 concepts.