Questions tagged [stringr]

The stringr package is a wrapper for the R stringi package that provides consistent function names and error handling for string manipulation. It is part of the Tidyverse collection of packages. Use this tag for questions involving the manipulation of strings specifically with the stringr package. For general R string manipulation questions use the R tag together with the generic string tag.

's stringr package provides a more consistent user interface to base-R's string manipulation and regular expression functions.

Repositories

Other resources

Related tags

2501 questions
1
vote
1 answer

R: Remove sub-string after a character but before another character

I'm doing some string cleaning, and I'm coming up on an issue. I have ~2,000,000 rows of address data that I need to clean up. Here is a small sample that I've made up: addresses <- c('123 Alphabet Road, Denver, CO', '% Andrew L. Doe P.O. BOX 123,…
Andy B
  • 49
  • 4
1
vote
0 answers

Unrecognized Escape and Object Not Found Errors in R Function

In trying to teach myself R, I was following along with the following example: https://www.r-bloggers.com/how-to-use-r-to-scrape-tweets-super-tuesday-2016/ In the example, the author, Kris Eberwein, describes the following function: score.sentiment…
DataProphets
  • 156
  • 3
  • 17
1
vote
1 answer

Complex multiple pattern replacement

I am trying to partially replace text within a string called "string1". There are multiple patterns contained in "LocateMe" which I would like to look for and replace with the same string of text: "!= -9999" The multiple patterns are quite complex…
user104435
  • 11
  • 1
1
vote
2 answers

Finding alphanumeric in R

I have character vector in russian language. See the sample vector below - x = "nНозологические единицы \r\n В20 Болезнь, вызванная вирусом иммунодефицита человека [ВИЧ], проявляющаяся в виде \r\nинфекционных и паразитарных болезней \r\n В21…
john
  • 1,026
  • 8
  • 19
1
vote
1 answer

Using str_match in stringr

I have many text files. In each text file, there is a section of interest (below): 发起时间 2015-04-08 回报机制
wwl
  • 2,025
  • 2
  • 30
  • 51
1
vote
3 answers

Text capture using pattern R - regular expression

Am trying to extract required words through pattern mapping. Below is the sample data in the object table +-----------+-------------------------------------------------------------------------------------------------+ | Unique_Id | …
Santosh
  • 91
  • 9
1
vote
1 answer

Cleaning forum post with multiple quotations in rvest + stringr

I am scraping a very long forum thread, and I want to come up with a database that has columns containing the following info: date / full post text / quoted user / quoted text / clean text The clean text should be each user's post, without the…
Nuria
  • 65
  • 5
1
vote
0 answers

How to give Backslash as replacement in R string replace

I need to ">" with "\". Example : "a>b" should be changed to "a\b" I have tried gsub > test <- "a>b" > gsub(">","\\",test, fixed = TRUE) [1] "a\\b" I have tried StringR str_replace > library(stringr) > str_replace(test,">","\\") [1] "ab" I have…
saiki4116
  • 323
  • 1
  • 4
  • 14
1
vote
1 answer

Extract string and its location using dplyr/tidyr approach

The input data frame has three id columns and one raw_text. u_id corresponds to user, doc_id corresponds to the document of a particular user and sentence id corresponds to a sentence within a document of a user. df <-…
x1carbon
  • 287
  • 1
  • 15
1
vote
1 answer

is this a bug of stringr::str_view in R?

I tried the following call in R and expected 'CCC' matched because it is supposed to be a greedy matching, str_view('ACCC','C{0,3}') but nothing matched. However the following call works fine ('A' is removed, then 'CCC' is…
Penguin Bear
  • 67
  • 1
  • 2
1
vote
1 answer

Regex and SharePoint names in R

I'm trying to extract names from a list produced by SharePoint. Each item in the list contains at least one name and a numeric id which varies in length. The format of the list looks like: all_projects %>% select(contact_names) A tibble: 116 x…
Dom
  • 1,043
  • 2
  • 10
  • 20
1
vote
2 answers

dplyr filter columns with multiple regex

I have two df in R (meta=some redundant info) df1: id value1 value2 value3 value4 id1_meta_meta-meta 4.93 13.93 16.8 35.39 id2_meta_meta-meta 28.63 45.43 30.52 61.71 id3_meta_meta-meta 3.35 1.26 7.98 …
sbradbio
  • 169
  • 1
  • 13
1
vote
3 answers

How to isolate a word next to a specified word

My dataframe has a variety of strings. See sample df: strings <- c("Average complications and higher payment", "Average complications and average payment", "Average complications and lower payment", "Average mortality and…
jesstme
  • 604
  • 2
  • 10
  • 25
1
vote
1 answer

Mutate rows based on maching to user defined strings that works universally

I have a data like this clas=c("CD_1","X.2_2","K$2_3","12k3_4",".A_5","xy_6") df <- data.frame(clas) > df clas 1 CD_1 2 X.2_2 3 K$2_3 4 12k3_4 5 .A_5 6 xy_6 and I would like to change some rows that match this condition if the strings…
Alexander
  • 4,527
  • 5
  • 51
  • 98
1
vote
1 answer

Count number of multiple pattern matches in a string

I would like to count multiple pattern matches in a dataframe column containing long strings. pattern<-c("AAA", "BBB", "CCC") df$AAA <- str_count(df$string_1, "AAA+") df$BBB <- str_count(df$string_1, "BBB+") df$CCC <- str_count(df$string_1,…
user2904120
  • 416
  • 1
  • 4
  • 18