Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R split string by symbol

Tags:

string

split

r

Example:

string = "abc|3g"
function(string)
Solution: --> "abc" "3g"

Is there any idea how to split in the way as showed in the example?

like image 593
Matt Avatar asked Jun 15 '15 09:06

Matt


People also ask

How do I split a string by Symbol in R?

To split a string in R, use the strsplit() method. The strsplit() is a built-in R function that splits the string vector into sub-strings. The strsplit() method returns the list, where each list item resembles the item of input that has been split.

How do I split a string into multiple spaces in R?

Method 1: Using strsplit() function strsplit() function is used to split the string based on some condition.

How do you separate a character vector in R?

Details. Argument split will be coerced to character, so you will see uses with split = NULL to mean split = character(0) , including in the examples below. Note that splitting into single characters can be done via split = character(0) or split = "" ; the two are equivalent.


1 Answers

strsplit(string,split='|', fixed=TRUE)

This is the possible answer. Other solutions?

like image 160
Matt Avatar answered Oct 14 '22 04:10

Matt