Questions tagged [strsplit]

strsplit is a function in R and MATLAB which splits the elements of a character vector around a given delimiter.

strsplit is a function in R (documentation) and MATLAB (documentation), which splits the elements of a character vector into substrings:

# R:  
strsplit(x, split, fixed=FALSE)
% MATLAB
strsplit(x, split);

Splits a character string or vector of character strings using a regular expression or a literal (fixed) string. The strsplit function outputs a list (R) or cell array (MATLAB), where each list item corresponds to an element of x that has been split.

  • x a character string or vector of character strings to split.
  • split the character string to split x.
    In R, if split is an empty string (""), then x is split between every character.
  • [R only:] fixed if the split argument should be treated as fixed (i.e. literally). By default, the setting is FALSE, which means that split is treated like a regular expression.
702 questions
-2
votes
2 answers

R split character vector using strsplit?

As a newbie in R how to treat correctly a variable having multiple values like that : x = c("1","1","1/2","2","2/3","1/3") As you see value 3 only appears in conjonction with others. To compute x further, the best would be to obtain 3 vectors like…
-3
votes
2 answers

strsplit symbol "|" lead to non-character error message in R

Thanks you very much for your help. Yes. I should provide a better example. Here is my input file (3columns.csv) Patients Markers Studies 1 AA EXX 1111 2 BB ABCB1 2222|3333|5555|6666 3 CC …
Catherine
  • 5,345
  • 11
  • 30
  • 28
-3
votes
1 answer

Php - string to array 3 dimensions

I come to you to find a solution to my problem: I have a flat string like this: $chaine = "519637824467582931832419576721894365346125789985376412698243157273951648154768293"; I want to convert this dimensional array chain, this format here: $tab =…
-3
votes
2 answers

strsplit by a particular character, provied that character should not be followed by a particular character

I want to split the string whenever it encounters "a", provided "a" should not be followed by "b" string <- "abcgualoo87ahhabta" I should get output as string <- [1]abcgua [2]loo87a [3]hhabta
-4
votes
1 answer

Spliting string into array based on curly brackets

For Example I have String like this: ""dear customer{Customer name} your reference number is {referenceNumber}" I want to get array=["{Customer name}",{referenceNumber}]" I have to split based on curly bracket inside bracket value is changeable…
-4
votes
2 answers

splitting the contents in the list in R

I have the following content in list "[4] {PIVOTAL GEMFIRE} => {HIBERNATE} 0.005952381 1.0000000 168.000000 2 \r" and i need to get it as: 4,{PIVOTAL…
Ellanti Kishore
  • 104
  • 1
  • 9
-4
votes
2 answers

How to iterate through the columns of a data frame efficiently?

So, data is a data frame consists of many columns, and one of which called lpep_pickup_datetime has date and time in the format of "01/01/2016 12:39:36 AM" I want to analyze these data by date and time, so I am trying to create a new column named…
user101998
  • 241
  • 5
  • 15
-4
votes
1 answer

strsplit in R using | as the pattern

I have a series of strings that I need to split on the character "|" for example: fruits <- c( "apples|oranges|pears|bananas", "pineapples|mangos|guavas" ) str_split(fruits, "|") Which outputs: [[1]] [1] "" "a" "p" "p" "l" "e" "s" "|" "o"…
Chloee Robertson
  • 195
  • 2
  • 12
-4
votes
1 answer

R Splitting the column into 2 with out changing other columns

I have my input. I am using R. I want solution in R id places present 1234 |new|world|life yes 5111 2012222 |lamp yes 123333 |world11|ness yes I want output id places …
user3619015
  • 176
  • 1
  • 1
  • 9
-4
votes
1 answer

Split 1 Column into 2 Columns in a Dataframe

Here's my data frame. > data Manufacturers 1 Audi,RS5 2 BMW,M3 3 Cadillac,CTS-V 4 Lexus,ISF So I would want to split the manufacturers and the models, like this, > data Manufacturers Models 1 Audi …
Bruce Brown
  • 217
  • 2
  • 4
  • 8
-5
votes
2 answers

How to split string in r by first appearance of some character

My data look like this: 106s(1m46s) 0s 15s 60s(1m) I want to receive only the seconds: 106 0 15 60 How to solve this problem ?
kenar
  • 1
  • 1
1 2 3
46
47