![]() |
VOOZH | about |
The strsplit() in R programming language function is used to split the elements of the specified character vector into substrings according to the given substring taken as its parameter.
Syntax: strsplit(x, split, fixed = FALSE, perl = FALSE, useBytes = FALSE)
Parameters: This function accepts some parameters which are illustrated below:
- x: This is the character vector, data file, or a string whose each element is going to be split.
- split: This parameter says to split the specified string X into the required formats.
- fixed: This parameter accepts logical values. If its value is TRUE, it matches and splits exactly, otherwise use regular expressions.
- perl: This parameter accepts logical values.
- useBytes: This parameter accepts logical values. If its value is TRUE, the matching is done byte-by-byte rather than character-by-character, and inputs with marked encodings are not converted.
Return value: This function returns a new split string.
Here we are going to apply this function in string.
Output :
[[1]] [1] "GFG" "is" "a" "CS" "Portal."
The delimiter is nothing but a character or value that is used to separate the words or text in the data. In the below example, strsplit() function is used with delimiter "//" that separates the words separated by the delimiter "//".
Output:
[[1]] [1] "GFG" "is" "a" "CS" "Portal."
In the below example, the texts are separated with the regular expression "[0-9]+" and strsplit() function is used to split those texts that are separated by that regular expression.
Output:
[[1]] [1] "GeeksforGeeks" "is" "a" "Computer" [5] "Science" "Portal."
In the below example, each character of the input string is being split with the help of strsplit() function.
Output:
[[1]]
[1] "G" "F" "G" " " "i" "s" " " "a" " " "C" "S" " " "P" "o" "r" "t" "a" "l" "."
In the below example, strsplit() function is used to split the specified date into each part like date, month, and year.
Output:
[[1]] [1] "20" "08" "2021" [[2]] [1] "12" "07" "2019" [[3]] [1] "02" "05" "2020" [,1] [,2] [,3] [1,] "20" "08" "2021" [2,] "12" "07" "2019" [3,] "02" "05" "2020"