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

R: use strsplit transform to list that is not length of 1

I was writing some code that need to inspect individual characters in a input string. I want to know whether there were numbers in string, and use strsplit to split the character into list. Then, use any() to check the numbers (the limitation is…
0
votes
1 answer

String split by value from another column

Hi I have this data frame (DF1) structure(list(Value = list("Peter", "John", c("Patric", "Harry")),Text = c("Hello Peter How are you","Is it John? Yes It is John, Harry","Hello Patric, how are you. Well, Harry thank you.")) , class = "data.frame",…
onhalu
  • 735
  • 1
  • 5
  • 17
0
votes
1 answer

Getting frequency of words from a pandas dataframe column

I have a dataframe that has the column cast which contains multiple actors from a movie. How do I count the number of times each actor appears in the dataset This is a snippet of what the column looks like df['cast'][:3] 0 João Miguel, Bianca…
0
votes
1 answer

How to split a string list into multiple lists in Python

I have the following list: x=['2 5 6 7', '9 11 13 15', '31 52 56 94'] My ultimate goal is to display it as table with columns and rows in jupyter notebook. This is what I have done so far: I converted the list into list of lists and now I have…
0
votes
1 answer

How to split merged/glued words with no delimiter using R

I'm scraping text keywords from this article page using rvest in R using the code below: #install.packages("xml2") # required for rvest library("rvest") # for web scraping library("dplyr") # for data management #' start with get the link for the…
Zawir Amin
  • 119
  • 1
  • 10
0
votes
1 answer

How to split duplicated separator in Python

I have a string with the format exp = '(( 200 + (4 * 3.14)) / ( 2 ** 3 ))' I would like to separate the string into tokens by using re.split() and include the separators as well. However, I am not able to split ** together and eventually being split…
wink
  • 57
  • 6
0
votes
1 answer

Split the rows in data frame based on timestamp using R

I have the below-unstructured ticketing dataset with the work notes update. Each ticket has multiple work notes based on timestamps. I need to split the Work notes column with each row having the timestamp and its corresponding update similar to the…
Akshi
  • 17
  • 6
0
votes
1 answer

How to split column names and drop parts of the names and convert data from wide to long format in R

I have data in the following format: dataset <- data.frame(taxa = c("k__Archaea| p__Crenarchaeota", "k__Archaea| p__Euryarchaeota", "k__Bacteria| p__[Thermi]"), "11908.MM.0008.Inf.6m.Stool" =c(0,1760,0), …
Hailey
  • 5
  • 2
0
votes
1 answer

Taking columns names, splitting them and melting them into a dataframe

I have a data frame of housing values spanning over 20~ years. The column names are the months and years i.e. 04-1996, 05-1996, 06-1996 and so on. I want to plot time series data for those months and years and have to take those column names and…
WittyAFC
  • 5
  • 3
0
votes
5 answers

How to remove leading zeros from the calculator expression in a string? python

I have a doubt, in python the string is, Z = "00123+0567*29/03-7" how to convert it to "123+567*29/3-7" Even I tried with re.split('[+]|[*]|-|/', Z) later with for i in res : i = i.lstrip("0") but it will split correctly, but to join back with the…
0
votes
1 answer

How to split one column into multiple columns with pipes acting as a separator

I'm trying to split the content below into multiple columns, separated by | or multiple pipes. For example, what you see below should have split into 8 columns. By the end of the week, you will have the opportunity to: | | Explain the accrual basis…
0
votes
2 answers

How to use seqinr::computePI on a list of character vectors

This is what the input data looks like (representative sample). sample1 MAQSVNIQDQYLNQ sample2 MAADRAQNLQDTFLNHV sample3 MAERSQNLQ I am trying to use the computePI() function from the seqinr library to perform a calculation on…
farinelli
  • 53
  • 6
0
votes
1 answer

How to include all data after using trimws function in R?

Example of 10 'Referer URl' is shown below https://www.google.com/ | query_string=utm_source=google&utm_medium=cpc&utm_campaign=121434112139&utm_term=&utm_content=Shirts&gclid=CXjadiOcHGGw6JEiJaf5zMhRxFk-AOtiXMOd_1szoBoCUEMQAvD_BwE |…
Anonymus
  • 13
  • 5
0
votes
2 answers

Splitting columns but not all new rows are created

I have a csv that looks like this: FIPS display_name Value 2013 "Aleutians East, (AK)" 172.9 2016 "Aleutians West, (AK)" 172.2 I want to split a column into 2 columns. I tried…
arg7
  • 1
0
votes
2 answers

how to split a text in an increasing manner

I have a small problem with which I need experts` advice. I need to split texts into pieces with different sizes. For example, one of the texts consists of 19578 words. what I want to do is to put the first 1000 words in the first piece, the first…