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
2 answers

R: strsplit in each column; Error: replacement element 1 has [y] rows to replace 1 rows

I'm working with a data frame (I'll call it 'letters') in R where there are 15 rows by 2 columns. Each column 2 contains a character string like "A|B|C|D|E". I want to split the string at each place a | appears to get the vector c("A", "B", "C",…
0
votes
2 answers

strsplit by dot and underscore and paste data into two columns

I have a list of dataset as per below example Match1 data.events.Brisbane.Broncos_Parramatta.Eels.sites.sportsbet.h2h data.events.Melbourne.Storm_North.Queensland.Cowboys.sites.sportsbet.h2h I want end results to be Team 1 Team…
0
votes
1 answer

R strsplit and filtering based on sub-indices matching in the logical vectors

I want to apply strsplit in such a fashion that if there exist an identical pair of values with & (e.g. this is one pair with & (NINA & SAM)) and also with | (e.g. this is another pair but with | (NINA | SAM)) then keep the one with & Below are 2…
Newbie
  • 411
  • 5
  • 18
0
votes
1 answer

how to transfomr list() into str_split?

I want to upgrade my server's PHP from 5.5 to 7, as I heard it will perform faster. I read in the documentation that: list() can no longer unpack string variables. str_split() should be used instead. Currently I have a string quantity variable…
rockyraw
  • 1,125
  • 2
  • 15
  • 36
0
votes
2 answers

How to set class objects from vector of string in c++

These are the data in my Login.csv file: ID,Name,Password,Gender 1,Liam,1234,M 2,Janice,0000,F So probably I'll use class & objects to create login details, and write it into the file. After that I will split the csv from file into a vector of…
JoJo
  • 3
  • 2
0
votes
1 answer

IndexError: list index out of range from rsplit output

I have a list of filepaths in a master file /home/tmp/dir1/file1.xml /home/tmp/dir2/file2.xml /home/tmp/dir2/file3.xml I am trying to extract the names like "file1", "file2", "file3", without the .xml or the leading filepath So in my code, I am…
ExceptionHandler
  • 213
  • 1
  • 8
  • 24
0
votes
2 answers

In R: Split a character vector to find specific characters and return a data frame

I want to be able to extract specific characters from a character vector in a data frame and return a new data frame. The information I want to extract is auditors remark on a specific company's income and balance sheet. My problem is that the…
user6149765
  • 15
  • 1
  • 4
0
votes
2 answers

Add new column and new value

I have a table called "new" and I wanted to extract year from ManufactureDate to a new column "year". new$ManufactureDate: 2014-01-01 2016-01-01 2005-01-01 1997-11-01 Create a new column and "new" will look like this: ManufactureDate …
Lara19
  • 615
  • 1
  • 9
  • 20
0
votes
3 answers

Regex with Positive lookhead still splits string in wrong place using strsplit()

I´m trying to split a character vector containing messages right in front of a date-time indicator. I was thinking about using strsplit() with a regular expression and perl = TRUE Here´s some example data: TEST <- c("05.10.17, 09:26 - Person One:…
Ju Ko
  • 466
  • 7
  • 22
0
votes
2 answers

R: head/tail on stringsplit

I need to rephrase my question, because i didn´t include other kinds of data in my data frame which cause a lot of problems when splitting by blanks. I´m really sorry! Important: blanks cannot be trusted all over the dataset, because they appear in…
rolling r
  • 1
  • 1
0
votes
3 answers

Strsplit reorder

**Given is a df ** df = data.frame(c("28A/38A/28C/00:05/00:05/00:05","93/00:20","93B/06:26","23A/87E/00:04/00:05","1A/38A/28C/28/00:05/00:10/01:05/00:20")) **I would like to reorder the strings and create 4 new columns* Example 1 with 1 Code and 1…
LePopp
  • 61
  • 6
0
votes
0 answers

"Error in strsplit (log, NULL): non-character argument" - Can't plot a scatterplot of a multiple regression

I'm trying to create a scatterplot of a multiple regressions model to check assumptions of the test but it seems to come up with the following problem: Error in strsplit(log, NULL) : non-character argument This is the line of code I have tried…
0
votes
2 answers

R data processing involving strsplit

I have a data frame which looks like this: > df V1 V2 V3 V4 V5 V6 V7 1 chr1:859582-899582 AHR.pfm 33440 - 9.188581 gcacgcaac NA 2 chr2:859582-899582 AIRE.pfm 7387 + 7.982141…
Newbie
  • 411
  • 5
  • 18
0
votes
2 answers

Partial matching of elements in two string columns in R

I have a large data grouped by two identifiers (Group and ID), Initial column that shows in an initial time period, and a Post column to show elements that occur following the initial time period. A working examples is…
0
votes
1 answer

R: Split character based on case in a dataframe

I need to split a column of names like "AbiesAlba" "GenusSpecies" into separate columns "Genus" "Species". GenusSpecies AbiesAlba AbiesAlba Needs to be: Genus Species Abies Alba Abies Alba I know I need to use something…