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

sapply an ifelse function on character vectors of varying length [r]

any assistance on my problem would be very appreciated, thanks. I have a data frame where the second column has had 'selected' words extracted from the first column (in previous steps) that have now often (but not always) left them in a different…
CallumH
  • 751
  • 1
  • 7
  • 22
1
vote
1 answer

str_detect(string = "", pattern = "^.*") returns FALSE

I expected str_detect (v1.0.0) could match anything with the pattern ^.* since the * should match 0 or more times. However, str_detect(string = "", pattern = "^.*") returns FALSE. Why doesn't it return TRUE, and is there an alternative pattern that…
wdkrnls
  • 4,548
  • 7
  • 36
  • 64
1
vote
1 answer

Detect excerpt of string from strings in a vector in R

Using a vector (a column of a data frame) of strings, I'm trying to identify the string from which an excerpt of a string comes. In the following example, excerpt_of_string is an excerpt (specifically the first 119 characters) from the second…
Joshua Rosenberg
  • 4,014
  • 9
  • 34
  • 73
1
vote
1 answer

extracting all .com, .in, .co.in from all elements

I have data in csv which contains following column ARTICLE_URL http://twitter.com/aviryadsh/statuses/528219883872337920 http://www.ibtimes.co.in/2014 I want to create an another columns next to this column where I can have only the web address like…
1
vote
1 answer

R: stringr to find the start location for rows

I can use stringr to find the start "http" location at first row, library(stringr) a <- str_locate(message[1,], "http")[1] a [1] 38 I want to find the start location for each row, and use "apply" fuction: message$location <- apply(message, 1,…
Jeffery Chen
  • 323
  • 2
  • 4
  • 13
1
vote
0 answers

Installation of package ‘stringr’ had non-zero exit status

Please help me to install stringr package in R. The result is: install.packages("stringi") Installing package into ‘C:/Users/kozlovpy/Documents/R/win-library/3.2’ (as ‘lib’ is unspecified) пробую URL…
Pavel Kozlov
  • 131
  • 1
  • 1
  • 4
1
vote
1 answer

str_extract in R to match a code combined of letters and numbers

I'm trying to extract an "ATC code" from a text string in R using the str_extract function in R. The code, within the string, always begins with "ATC: ", then the code itself is a combination of letters and numbers strung together. The current…
Sam Gilbert
  • 1,642
  • 3
  • 21
  • 38
1
vote
1 answer

R, stringr::str_extract_all: Get all occurences specified in regex list

Really simple, but I can get the 'greediness' of regex to work like I want. Say you have: unlist(stringr::str_extract_all("XXXXSXTXXX","([A-Z]{2}[T|S][A-Z]{2})")) This gives only the first match: [1] "XXSXT" How can I change the regex behaviour to…
user3375672
  • 3,728
  • 9
  • 41
  • 70
1
vote
1 answer

SparkR, worker cannot load library

I recently start using SparkR. I have 1 master and 3 worker running and AWS. I am using RSudio Server. My codes involve stringr package, and this packages have been installed to /usr/share/R/library on all nodes. But when I run SparkR:::map(data,…
user2146141
  • 155
  • 1
  • 14
1
vote
1 answer

Extract and paste multiple elements from a list of lists generated by strsplit

I am trying to extract and paste together elements of a list of lists generated using strsplit. For example: cat<-c("X0831_d8_f1_2s_wt_8_ROI_009", "X0831_d8_f1_2s_wt_8_ROI_008", "X0831_d8_f1_2s_wt_8_ROI_007", "X0831_d8_f1_2s_wt_8_ROI_006",…
Damian
  • 516
  • 1
  • 4
  • 20
1
vote
2 answers

Str_extract not working

I am trying to extract the first time stamp from the following character: "WHENSEPTEMBER 14, 2015 @ 11:56 AM - 12:00 PM EDT" I have a whole list of them and they are vectors, as required. > is.vector(data$description) [1] TRUE >…
user3859248
  • 97
  • 2
  • 11
1
vote
4 answers

stringr package str_extract() with inversion of the regex

I have a string like the following: 14ed0d69fa2.bbd.7f5512.filter-132.21026.55B67C8E27.0 The following regex extracts the last part that ends in a dot and a digit. I want to extract everything but that part and can't seem to find a way to invert…
Gopala
  • 10,363
  • 7
  • 45
  • 77
1
vote
2 answers

Regex for known start and end characters in Perl and R-lang

I'm looking to match mentions of foo in a username. I need to be able to match text strings that start with '@' and contain the word 'foo' at any location within that username, ending by either a space or grammar. I neeed to be able to match:…
lmcshane
  • 1,074
  • 4
  • 14
  • 27
1
vote
2 answers

Extracting strings from different columns and tidying data in R

I am trying to extract a strings of the movie type from a data set. The data is in the following format where the genre types are randomly distributed in the dataset by different reviewers.Luckily there are only 4 genre types (comedy, action,…
user3570187
  • 1,743
  • 3
  • 17
  • 34
1
vote
1 answer

Replace string content with arbitrary number of four characters in middle of string?

Goal: turn x into y; where x has an arbitrary number of spaces, \rs, and \ns. x <- "some text, \r\n \r\n)more text" y <- "some text)more text" I've made a few attempts using…
mef jons
  • 232
  • 1
  • 3
  • 10