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

RegEx and stringr package

I am an R newbie and have troubles with my programming homework. The input is a poem: poem <- c( "Am Tag, an dem das L verschwand,", "da war die Luft voll Klagen.", "Den Dichtern, ach, verschlug es glatt", "ihr Singen und ihr Sagen.", …
1
vote
1 answer

How do I change " " characters to normal spaces in R

I am using R for web scraping and I have a script that copies the text of a link and then uses this string to follow the link using RSelenium. Unfortunately this does not seem to work for one particular string when I run the script, but when I…
iProcrastinate
  • 131
  • 2
  • 7
1
vote
2 answers

Regex and file processing

This question relates to R but really isn't language specific per se. I have a bunch of csv files with this general format "sitename_03082015.csv". The files have 5 columns and various rows Host MaximumIn MaximumOut AverageIn …
JohnP
  • 65
  • 1
  • 6
1
vote
1 answer

Regular expression in r. Grouping & Capturing

I'm trying to use regexp in R cran, using the library stringr. I was studing str_match and str_replace functions. I don't understand why they give different results when I use parentheses for Grouping : library(stringr) s<-"(.+?)( PIAZZALE |…
dax90
  • 1,088
  • 14
  • 29
1
vote
1 answer

Using stringr's word() to repeat and group a sentence

Here's a fun one. I'm trying to do exactly what this post is doing. That is, repeating and grouping words. The catch with this question is that I'd like to do it purely with stringr's word() function with a paste0 wrapper. Take the following…
Rich Scriven
  • 97,041
  • 11
  • 181
  • 245
1
vote
2 answers

R Regular Expressions: How do I get the full matched string

I am trying to get the full RegEx match out from R, but I can only seem to get the first portion of the string. Using http://regexpal.com/ I can confirm that my RegEx is good and that it matches what I expect. In my data, the "error type" is found…
1
vote
2 answers

R remove only "[" "]" from string

I have a something like : test[1] "[0 30.5 4.5 10.5 2 35 22.999999999999996 29 5.500000000000001 23.5 18 23.5 44.5 3 44.5 44.00000000000001 43 27 42 35.5 19.5 44.00000000000001 1 0 31 34 18 1.5 26 6 45.99999999999999 10.5 9.5 24 20 42.5 14.5 45.5…
delaye
  • 1,357
  • 27
  • 45
1
vote
2 answers

removing left hand side parenthesis in str_split in r

How can I make this work in R? str_split("U.S. (California, San Luis Obispo County)",pattern=' (') Error in gregexpr("(", "U.S. (California, San Luis Obispo County)", fixed = FALSE, : invalid regular expression '(', reason 'Missing…
yonicd
  • 498
  • 1
  • 4
  • 15
1
vote
1 answer

Extract Information from Text in R

I am working on Entity Extraction in R. I have a UniqueID and Text field - need to extract location information from the text field. My Text field has description with location names text <- c("SERANGOON JC","Blk 4","SHELL TAMPINES AVE 4","SENOKO…
Prasanna Nandakumar
  • 4,295
  • 34
  • 63
1
vote
2 answers

Strange behavior of stringr-based function

In order to change values in results data frame, I use a stringr-based function, recommended in an answer by Hadley Wickham (https://stackoverflow.com/a/12829731/2872891). I left the function intact with the exception of changing df in the end to…
Aleksandr Blekh
  • 2,462
  • 4
  • 32
  • 64
1
vote
2 answers

Extract Phone Numbers from a string in R

I am working on extraction from a text - using 'stringr' package in R.I found this example: strings <- c(" 219 733 8965", "329-293-8753 ", "banana", "595 794 7569", "387 287 6718", "apple", "233.398.9187 ", "482 952 3315", "239 923 8115", "842 566…
Prasanna Nandakumar
  • 4,295
  • 34
  • 63
1
vote
2 answers

Vectorisation of a similar string finding loop

I have a large vector of strings like this: d <- c("herb", "market", "merchandise", "fun", "casket93", "old", "herbb", "basket", "bottle", "plastic", "baskket", "markket", "pasword", "plastik", "oldg", "mahagony", "mahaagoni", "sim23", "asket",…
Crops
  • 5,024
  • 5
  • 38
  • 65
1
vote
2 answers

Finding the count of each word in a classification using stringr

I am trying to match two sets of words with number of strings. The two sets of words are car and school, and using the stringr package I've set it up to match any instance of a word from either car or school. library(stringr) car <- c("Honda",…
ATMA
  • 1,450
  • 4
  • 23
  • 33
1
vote
2 answers

stringr split column by alpha and numeric

I can only use stringer/ regular expression, I am working in r I have a csv I have downloaded called mpg2,and a subset of this containing only Mercedes Benz makes. What I am trying to do is split the model into alpha and numeric so I can plot them.…
hk47
  • 127
  • 3
  • 14
1
vote
3 answers

Split street address into street number and street name in r

I want to split a street address into street name and street number in r. My input data has a column that reads for example Street.Addresses 205 Cape Road 32 Albany Street cnr Kempston/Durban Roads I want to split the street…
Carmen
  • 117
  • 1
  • 7