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

Wrapping a string into a set number of lines

I have a set of strings such as x <- c("xxx", "xxx xxx", "xxx xxxx xxx", "xxx xxxx xxx xxxxxx") and I want to wrap each so that they fall over two lines, with the breaks where there are spaces, roughly in the middle of the strings, i.e. an output…
guyabel
  • 8,014
  • 6
  • 57
  • 86
0
votes
1 answer

Split a column of a dataframe into two separate columns

I'd like to split a column of a dataframe into two separate columns. Here is how my dataframe looks like (only the first 3 rows): I'd like to split the column referenced_tweets into two columns: type and id in a way that for example, for the first…
mOna
  • 2,341
  • 9
  • 36
  • 60
0
votes
0 answers

I'm trying to "create" an alphabet in PHP, which my gf and I can only understand, but im facing some problems here

Can someone please help? As it says in the title, im trying "create" an alphabet in PHP, which my gf and I can only understand (it's a little thing that i thought to have with her), but im facing some problems. I have this code here in HTML and PHP…
Manuel
  • 3
  • 1
0
votes
1 answer

Splitting a string and creating a variable out of the splits

Is it possible to split a string and then use the split to create new variables? For example, data is "Red", "Blue", "Red Blue", "Red Blue Green" I would like to capture those who selected "Red", "Blue", "Green" in a matching "True/False" variable…
0
votes
1 answer

In R, convert/split 1-column dataframe into 4 columns based on splitting content in strings

This feels like a fairly difficult data manipulation / dataframe fixup issue in R. We have the following messy dataframe, currently organized such that multiple columns of information are packed into the X2 column. Using fake names, emails, phone…
Canovice
  • 9,012
  • 22
  • 93
  • 211
0
votes
2 answers

split a string from end till second space

I have a string i want to split it so that I can extract the name from the particular string. let str = "CN=John Mcclau - i0c00cu,OU=PET_Associates,OU=Users,OU=PET,DC=officecabs,DC=SAT-PET,Dt=com"; let splitstr= str.substr(3, str.indexOf('…
sd_30
  • 576
  • 1
  • 6
  • 21
0
votes
2 answers

R: find number of columns > 0 per row for a group of column names with a partial string match

I have a dataframe that resembles the following: ID X Y A_1_l A_2_m B_1_n B_2_l C_1_m C_2_n C_3_l w X Y 0 0 0 0 0 0 0 x X Y 0 0 3 0 0 0 0 y X Y 0 1 0 4 0 1 0 z X Y 3 4 5 6 2 1 5 The first letter denotes a sample, the number a…
keenan
  • 462
  • 3
  • 12
0
votes
1 answer

R split column names with different occurrences of delimiter into strings and assign unique strings/string counts to a new dataframe

I have a large dataframe with column names like this. I am not trying to work with any data yet, just the column…
keenan
  • 462
  • 3
  • 12
0
votes
2 answers

Smarty equivalent for str_split()

Im looking for an equivalent for str_split() in Smarty as {php}{/php} looks like deprecated and not very clean. I came across explode but it needs a delimiter and what I'm trying to get is: 1/2/3/4/5 from $chars = str_split(12345); foreach($chars…
David
  • 213
  • 3
  • 10
0
votes
1 answer

Python: Extract unique sentences from string and place them in new column concatenated with ;

Afternoon Stackoverflowers, I have been challenged with some extract/, as I am trying to prepare data for some users. As I was advised, it is very hard to do it in SQL, as there is no clear pattern, I tried some things in python, but without success…
GregLu
  • 1
  • 1
0
votes
1 answer

Split the text column with varied length and no pattern to multiple columns using delimiters in R

I have some 13 column and 20,000 rows of data. In which one column is having description details. Description column has one or many values separated using delimiters like ",", "-", "/", "&". Need to split the Description column into multiple…
Arun Laksh
  • 25
  • 4
0
votes
1 answer

Two string columns with stored datapoints - access one by the other

i have a dataframe with basically two columns and "dates" in one and "grade of disease" in the other. They are coded as…
0
votes
1 answer

R: split a string in a dataframe column

I have a dataframe in which one of the columns contains strings. I'd like to split that strings, separated by a dot, and keep always the first part. This would be my dataframe: State 1 This is…
MustardRecord
  • 305
  • 4
  • 14
0
votes
1 answer

Split text with stringr::str_split in location preceding specific pattern (numeral or text)

Assuming that I have a table of strings: df <-tibble::tribble( ~ alternatives, " 23.32 | x232 code | This is a description| 43.11 | a341 code | some other description | optimised | v333 code | still another description" ) I would like to split the…
Jacek Kotowski
  • 620
  • 16
  • 49
0
votes
0 answers

R Find unique value and find record like %_%

I have a data table of 10,000 records having multiple columns. Below is the code and part of the data set states <- str_trim(unlist(strsplit(as.vector(search_data_set$location_name), ";")) Part of Dataset: Maine Virginia; Oklahoma; Kansas…