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

Split dataframe column based on specific list of words

Is it possible to split strings from a dataframe column based on a list of words? For example: There is a dataframe with a column Company, each record includes the company name, a legal form, and sometimes additional information after the legal form…
hazen23
  • 29
  • 4
0
votes
1 answer

Extract specific portion of a string and paste to a new column in R

I have the following dataframe with a string column and I want to extract T,N,M,G,L status (and so on..) for each observation into separate new columns including their respective prefix and suffix. I have tried the grep() and strsplit function but…
0
votes
2 answers

iterating list in python and splitting based on condition

I am trying to filter the list of values and store in a new list elements that have .xls and .csv extensions to it. However I don't get the full string output I want to .. Reference data Edit : Updated the dummy dataset with other categories (…
EricA
  • 403
  • 2
  • 14
0
votes
5 answers

Is there a R function to strsplit specifc rows under one column based on another column?

I am having a data frame (for example as below: name student_id age gender Sam 123_abc_ABC 20 F John 234_bcd_BCD 18 M Mark 345_cde_CDE 20 M Ram xyz_111_XYZ 19 M Hari uvw_444_UVW 23 M Now, I need a new column as…
amu
  • 13
  • 3
0
votes
3 answers

Creating a matrix by splitting a vector

The string: f <- c("20-04-2018","15-07-2021","11-11-2022","08-12-2021","28-01-2020") Allocate one column for the day, month and year. Anyone who knows what code to use to solve this question?
0
votes
4 answers

How do I split a website URL with multiple separators in JavaScript?

I'm trying to create a Custom JavaScript Variable in Google Tag Manager to split up information from a page url that has multiple separators. For example, in https://website.com/item/2006-yellow-submarine, I would want to capture the 2006. I've been…
0
votes
3 answers

Splitting data in column based on a word

Is there a code to create a column with only the speed number? In the Cpu column, as included in the image, too much unnecessary information is included for me. I only want the ''Ghz''number (f.i. 2.3, 1.8 and 2.5).
0
votes
1 answer

Tracing where the original character was

I am trying to create a function where I can split a sequence of letters such as that shown below. SCDKSFNRGECSCDKSFNRGECSCDKSFNRGEC I want to be able to split the sequence after every C and can do that using the following code: TestSequence <-…
AJSmith993
  • 25
  • 3
0
votes
2 answers

Print 1st word of each sentence in text using python

How to ignore text inside (). In below example I have to ignore printing directions) & Over right). Example: Text = "A paragraph is a self-contained unit of discourse in writing dealing with a particular point or idea. A paragraph consists of one or…
0
votes
2 answers

How to Add Two Columns of DataFrame and Rename it with Prefix Name

The original Data looks like ID, kgp11274425_A, kgp11274425_HET, kgp5732633_C, kgp5732633_HET, rs707_G, rs707_HET, kgp75_T, kgp75_HET 1 C T G T C A 0 0 2 C …
user17063641
0
votes
2 answers

Splitting string column into a few columns - keep the null entries

Dear kind people of the internet, I need help. I am trying to split a string column into several columns and keep the null/NA entries. df <- cSplit(df, "question", "_") This code currently splits them but removes the null entries and shows the…
Thandi
  • 225
  • 1
  • 2
  • 9
0
votes
1 answer

Split string at a vertical bar character "|"

I feel like this question is asked a lot but all the solutions I found don't work for me either. I have a dataframe with a column (called ID) in which I have a string of numbers and letters (e.g: Q8A203). In a few rows there are two of those…
Marlop
  • 17
  • 4
0
votes
1 answer

Split string based on capitalized word using r

I have a string that I would like to split into several strings. library(stringr) testString <- "SMITH, Klaus, text, text, SMITH, Samantha, text, text, MUELLER, Klaus, text, text, MUELLER, Klara, text, text" Whenever a new word is completely…
JohnnyKing
  • 29
  • 5
0
votes
1 answer

how to use strplit in tidyverse dataframe

I have a data frame in R with several columns. In one column, I want to use strsplit to extract part of the string and put it into another column. I have a data frame with a column called IDName, the IDName has strings in this…
mans
  • 17,104
  • 45
  • 172
  • 321
0
votes
0 answers

str = str.split(",") AttributeError: 'NoneType' object has no attribute 'split' building a client for an online game running into this error

class Player(): def __init__(self, x, y, width, height, color): self.x = x self.y = y self.width = width self.height = height self.color = color self.rect = (x,y,width,height) self.vel =…
Juice
  • 1