strsplit() method in R Programming Language is used to split the string by using a delimiter.
Syntax: strsplit(string, split, fixed)
Parameters:
string: Input vector or string.
split: It is a character of string to being split.
fixed: Match the split or use the regular expression.
Return: Returns the list of words or sentences after split.
Here, we are using strsplit() along with delimiter, delimiter is a character of an existing string to being removed from the string and display out.
# R program to split a string # Given String gfg < - "Geeks For Geeks" # Using strsplit() method answer < - strsplit(gfg, " ") print(answer)
Output:
[1] "Geeks" "For" "Geeks"
Here, we are using regular expressions in delimiter to split the string.
# R program to split a string # Given String gfg <- "Geeks9For2Geeks" # Using strsplit() method answer <- strsplit(gfg, split = "[0-9]+") print(answer)
Output:
[1] "Geeks" "For" "Geeks"
We can also manipulate with date using strsplit(), only we need to understand the date formatting, for example in this date( 2-07-2020) following the same pattern (-), so we can remove them using delimiter along with “-“.
string_date<-c("2-07-2020","5-07-2020","6-07-2020", "7-07-2020","8-07-2020") result<-strsplit(string_date,split = "-") print(result)
Output:
[[1]] [1] "2" "07" "2020" [[2]] [1] "5" "07" "2020" [[3]] [1] "6" "07" "2020" [[4]] [1] "7" "07" "2020" [[5]] [1] "8" "07" "2020"
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.