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

Split the String in Powershell

I have a code which gives me below output. assigned_to @{display_value=Raju Mishra link=https://googleprod.service-now.com/api/now/v1/table/sys_user/6486d149db70ee40db88b9d10f961969 } Desired Output Username Raju Mishra With below command, I am…
GURU SINGH
  • 149
  • 7
0
votes
0 answers

My gsub is not working for my string, why?

this is my string: x <- "NINSGSMN019VLKM6NINSGSMN05ZISGPBNINSGSMN04K36312NINSGSMN07AQ74H6NINSGSMN08LVCE18NINSGMDN0E57CIF6" I want to change it to "NINSGSMN019VLKM6" "NINSGSMN05ZISGPB"…
0
votes
1 answer

Error in strsplit(M[, Field], sep) : non-character argument when using the Bibliometrix functions NetMatrix and cocMatrix?

I'm working with the bibliometrix package, functions cocMatrix and biblioNetwork. I read my data, M from an Excel spreadsheet: M <- readxl::read_xlsx("prueba.xlsx") Here is a sample: structure(list(AU = c("CALIXTO-FLORES R", "TINOCO-IZQUIERDO W;…
0
votes
1 answer

Split or text-to-column a header cell in python, pandas, openpyxl

I would like some advice on how to split a excel header cell using python, pandas, or openpyxl (what I'm currently trying to learn. This is something that I've done in excel/vba using text-to-columns. But I'm coming up with errors while trying to…
Boomer
  • 229
  • 1
  • 9
0
votes
1 answer

Convert one column to many using a separator

Having a dataframe like this: data.frame(id = c(1,2), text = c("Google,Amazon", "Amazon,Yahoo"), stringsAsFactors = FALSE) # id text # 1 1 Google,Amazon # 2 2 Amazon,Yahoo How is it possible to create from text column using as…
Nathalie
  • 1,228
  • 7
  • 20
0
votes
0 answers

About string split method in java

In java split method when we split the sentence by "." . Why we write "\." instead of "." ?? But when we split the sentence by comma we use only ",".
0
votes
2 answers

r - Just split if there is no space before separator

does someone know a way to split string using at a certain string but just if there is no space before? Maybe even using the strsplit function? Here is an example: input_str = "For example. Production of something a Product.ProIts cool" I want to…
Chris
  • 35
  • 3
0
votes
1 answer

Regex to extract two specifc words from string

I am parsing some files and I had planned to extract the information from somewhere within the file, but this failed due to special characters. The words I need are still contained in the filename but there is also other stuff in there. I am…
Max M
  • 806
  • 14
  • 29
0
votes
1 answer

How to split strings separated by many semicolons in R?

My desire is to know the length of a certain text separated by ; which comes after any number. In the text named txt below, I don't want to consider the first two semicolons. To get the length, the ; comes after 6, 5 should be considered. I mean the…
iGada
  • 599
  • 3
  • 9
0
votes
1 answer

split a string but keep together certain substrings

I want to split a character column in a data frame by certain separating characters (i.e. white spaces, commas and semicolons). However, I want to exclude certain phrases (in my example I want to exclude "my test") from the split. I managed to get…
deschen
  • 10,012
  • 3
  • 27
  • 50
0
votes
2 answers

Changing cell values in a row conditioned on values of another row

I'm trying to change a data frame with several thousands of rows that each look like one of the following variations: table, th, td { border: 1px solid black } …
0
votes
1 answer

Why can't I extract only the first word of the fields of a column with loop for in r?

Can anyone help me with this simple task. I'm getting started in r, and I can't understand why this part of code isn't running inside a loop for. I've tried to use the function strsplit() out of the loop and it worked well, but I'm not succeding…
0
votes
2 answers

split rows of a column then make a column with the 2nd element R

This is hard for me, so please help me with this. I have a df that look like: col1 col2 col3 ccd_x29807 Gly_GCC_89 0.3 ccd_x29807 Gly_GCC_87 0.3 ccd_x29807 Gly_GCC_88 0.3 ccd_x20463 Lys_CTT_12 0.1 What I want to do is to save the values…
Apex
  • 1,055
  • 4
  • 22
0
votes
2 answers

Conditionnaly split strings cells in a dataframe R

I have a dataset with species name where some names originally used are now obsolete, so they are noted "old_species***retired*** use new_species", whereas correct cells are just noted "new_species". Here is a sample of the data : df<-…
christophe
  • 25
  • 5
0
votes
0 answers

trying to summarize survey data for questions with 'select all that apply' using R

We have a survey that asks for 'select all that apply' so the result is a string inside quotes with the values separated by commas. i.e. "red, black,green" There are other question about income so I have a factor with 'low, medium, high' I want to…
Mike B.
  • 1
  • 2
a b c