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

using nested functions in do.call in R

I have a data.frame named df with one column named Text, consisting of some sentences, and I want to add a new column named Length equal to number of words in the Text column. So, my data.frame looks like this: Text 1. First sentence. 2.…
Mehdi Abbassi
  • 627
  • 1
  • 7
  • 24
0
votes
2 answers

How can I apply str_split to a tibble with one character column?

Suppose I have a tibble object with one character column; and I want to transform to the target by using str_split function. I cannot succeed in this. Any suggestions for that? >…
Z. Zhang
  • 637
  • 4
  • 16
0
votes
1 answer

How to read a comma-separated numerical string and perform various functions on it

I have a column with numerical comma-separated strings, e.g., '0,1,17,200,6,0,1'. I want to create new columns for the sums of those numbers (or substrings) in the strings that are not equal to 0. I can use something like this to count the sum of…
Vjain
  • 13
  • 2
0
votes
1 answer

Using str_split to fill rows down data frame with number ranges and multiple numbers

I have a dataframe with crop names and their respective FAO codes. Unfortunately, some crop categories, such as 'other cereals', have multiple FAO codes, ranges of FAO codes or even worse - multiple ranges of FAO codes. Snippet of the dataframe with…
prayner
  • 393
  • 1
  • 10
0
votes
1 answer

Split String after first slash using postgresql

I have multiple string where i want to split my string after first slash if it matches to specific pattern. But I am not finding way for it. I am using postgresql. Split_column PA067 PA089/GHC PA001/FDCJ/988S After PA---, there xan be 0 to n…
0
votes
1 answer

Extract right part of a character string in R using STRSPLIT and multiply it by 100

I'm looking forward to extract the numbers of a character string. Unfortunately, I'm getting the left part of it. Data: > T3_C2_Z2_Stata_S [,1] [1,] "Min. :-0.0031685 …
Fabricio
  • 35
  • 5
0
votes
2 answers

Need to separate strings into multiple variables based on numeric versus non-numeric

I have a data frame with one variable. It looks something like this: df <- data.frame(c("25 Edgemont 52 Sioux County", "57 Burke 88 Papillion-LaVista South")) To provide more context, each observation/row is a basketball game score. I would like to…
Jeff Swanson
  • 45
  • 1
  • 8
0
votes
1 answer

Convert comma separated column into multiple columns

I have a dataset of film with several columns, one of which is a column for country. Because some films are produced by more than one country, the film can have different countries at the same time in the "country" column. For example, enter image…
0
votes
1 answer

How to modify get_text function of BeautifulSoup according to required formatting?

I want to scrape this webpage. I'm using BeautifulSoup. url="https://www.blockchain.com/btc/block/00000000000000000011898368c395f1c35d56ea9109d439256d935a4fe7d656"…
0
votes
1 answer

Split two words connected by a dot

I have a big dataframe with news articles. I have noticed that some of the articles have two words connected by a dot as the following examples shows The government.said it was important to quit.. I will conduct some topic modelling, so I need to…
Jose David
  • 139
  • 9
0
votes
2 answers

How to determine the lines, and how many words in my song using split() in python

Music lyrics Look what you made me do, I'm with somebody new Ohh, baby, baby, I'm dancing with a stranger I tried using re.split also tried loop.
0
votes
1 answer

Split without separator with diferent arrays

Could you, please, help me? I need to split a string that doesn't have a separator. I need to split the string in different types. For example, the following strings should generate the same list as output: "ak = bib+c*(data+1005) " " ak= bib…
jonss
  • 9
  • 2
0
votes
2 answers

Time Difference between per person between consecutive rows

I have some data which (broadly speaking) consist of following fields: Person TaskID Start_time End_time Alpha 1 'Wed, 18 Oct 2017 10:10:03 GMT' 'Wed. 18 Oct 2017 10:10:36 GMT' Alpha 2 'Wed, 18 Oct 2017…
Sandy
  • 1,100
  • 10
  • 18
0
votes
3 answers

R: using strsplit in a tibble column

I have a tibble and in one of the columns are strings. They are names of instruments that respondents to a survey said they played. I would like to capture each instrument as it's own separate string. Values in this column range from one single…
Jay Wehrman
  • 193
  • 2
  • 10
0
votes
2 answers

How to split a single column into multiple column using range (Start-End) values in R?

I have a text file with multiple values, however, there is no delimiter to differentiate this when loaded into R. There is a secondary file that defines each of the columns based on a start and end position. I tried to go through the solutions that…
RBK
  • 375
  • 2
  • 5
  • 12