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
0
votes
1 answer

Conditionally split single cells

I have this data.frame and I want to identify which cells from sample1$domain have "www", replace that with "" and strsplit the corresponding sample1$suffix. The data looks like this: domain suffix 1 wbx2 …
Sotos
  • 51,121
  • 6
  • 32
  • 66
0
votes
3 answers

How to split a string of text after a certain amount of words and numbers in R?

I would like to split my text at 8 words and numbers after it encounters a time. Example of the text: s <- 'random random random 19:49 0-2 H 2 ABC TREE LAKE #88 TURTLE random random 03:32 43-21 V 8 XYZ LOG #72 FIRE random random random' Example of…
Dre
  • 713
  • 1
  • 8
  • 27
0
votes
0 answers

Can't explode a method in php

What do I missed in my code ? I tried to explode/split a method but the result is empty array. Here's my code: function fileName($id){ $result = mysql_query("SELECT * FROM folders WHERE folder_id = ".$id.""); $row = mysql_fetch_array($result); …
Hendrik Eka
  • 145
  • 3
  • 14
0
votes
2 answers

How to split words in R while keeping contractions

I'm trying to turn a character vector novel.lower.mid into a list of single words. So far, this is the code I've used: midnight.words.l <- strsplit(novel.lower.mid, "\\W") This produces a list of all the words. However, it splits everything,…
Stefano
  • 25
  • 7
0
votes
0 answers

Extracting String in R

I am wanting to extract strings from elements in a data frame. Having gone through numerous previous questions, I am still unable to understand what to do! This is what I have tried to do so far: unlist(strsplit(pcode2$Postcode,"'")) I get the…
Amit Verma
  • 95
  • 1
  • 1
  • 6
0
votes
1 answer

PHP str_split on string with decoded html_entity

If I run this code: I get this result: array (size=28) …
Dentra Andres
  • 371
  • 1
  • 7
  • 18
0
votes
1 answer

Problems and error in strsplit

I use the following commands: sequence <- '<{EADFE20F543836047330DEFFB893127AF536560121698ADE2FCE6985E07A40D8 SELECT;DD2E595CF23E65E128560B655E0C6848 SELECT}>' v1 <- trimws(gsub('[[:punct:]]+', '', sapply(strsplit(sequence,…
Avi
  • 2,247
  • 4
  • 30
  • 52
0
votes
1 answer

Manipulate char vectors inside a data.table object in R

I'm a bit new still to using data.table and understanding all its subtleties. I've looked in the doc and in other examples in SO but couldn't find what I want, so please help ! I have a data.table which is basically a char vector (each entry being a…
Fagui Curtain
  • 1,867
  • 2
  • 19
  • 34
0
votes
2 answers

Unlist data frame column wihtout losing information from other column

I have found a post, which is very similar to my problem. I have a data.frame with a list of keywords, which are separated by semicolons in one coloumn and the year in another column. I would like to unlist the keywords without losing the…
PeterGerft
  • 49
  • 1
  • 7
0
votes
1 answer

Split string in R by \ character

I have column sr$classf in sr dataframe with string like hierarchy servicegroup\service\servicerequest\. I want to split string with strsplit() by \ character and put different parts of splitted string in additional columns. For example I create…
0
votes
3 answers

How to parse key value pair of url string in R with multiple conditions

I have a string in the below format: a <- c("first_name=James(Mr), cust_id=98503(ZZW_LG,WGE,zonaire), StartDate=2015-05-20, EndDate=2015-05-20, performance=best") My aim is to get the final result in a dataframe as below: first_name …
maddy kemen
  • 67
  • 2
  • 9
0
votes
2 answers

Midpoint between range in R

I have a column that has estimated numbers for a conversion rate that looks like; Type Conversion A 90 B 84 C 85-90 D 60-70 The problem is, I need to create a new column that takes the midpoint if the conversion was given in a…
chattrat423
  • 603
  • 2
  • 11
  • 24
0
votes
2 answers

Split specific strings in a vector using regex

I have a vector of strings, some of which include punctuations/symbols. For example: words <- ("hi", "my.", "name!", "is98", ""joe"") My goal is to create a vector that has all these words, but the punctuations, numbers, and symbols are made into…
NeonBlueHair
  • 1,139
  • 2
  • 9
  • 22
0
votes
3 answers

strsplit with non-character data

1I want to do a strsplit on one variable ID1 to split into ID1_s1 and ID1_s2 and I need to get rid of the strings that are in brackets. # dummy data df1 <- data.frame(ID1=c("Gindalinc","Xaviertechnolgies","anine.inc(Nasq)","Xyzinc"),…
user3570187
  • 1,743
  • 3
  • 17
  • 34
0
votes
1 answer

SimRAD users: fasta import to prevent insilico.digest strsplit error

I'm trying to use the code below to do an in silico digestion for a RADseq run within the package SimRAD. I believe the problem is with the loading of the data - I keep getting the following error: Error in strsplit(DNAseq, split =…
AmyK
  • 1
  • 1