Skip to main content
The 2024 Developer Survey results are live! See the results

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.

stringr
3 votes
5 answers
77 views

Order columns based on suffix with dplyr and stringr

I have a dataframe that has columns that are separated out by suffix see ex_df. Each time I run the code there may be varying column amounts based on database entries so I am trying to find a way to ...
JasminL0p3z's user avatar
0 votes
1 answer
33 views

Remove string from column across group of rows in another column

I would like to remove a string from one column across a group of rows in another column. In the below reprex, I would like to remove the string in snippet from the string in text in any row in the ...
maia-sh's user avatar
  • 557
3 votes
2 answers
94 views

Using R, how can I detect if a string includes a unicode character?

If a string includes a Unicode character, I would like to detect it and replace it (because RMarkdown fails when creating pdf output that includes Unicode characters). For example, the variable ...
Judy 's user avatar
  • 182
1 vote
0 answers
48 views

Convert ordinal word string to ordinal number string? [duplicate]

Suppose I have a vector containing ordinal number words as strings in R: ordinal_words<-c("FIRST COMPANY", "BAKERY FIFTH AVENUE", "WEST FORTIETH WAY") I would like ...
James Rider's user avatar
6 votes
7 answers
316 views

Count empty strings?

In R, suppose I have a vector like: vector<-c("Red", " ", "", "5", "") I want to count how many elements of this vector are just empty strings ...
James Rider's user avatar
1 vote
1 answer
24 views

Changing isolated words in R?

In R, I have a character vector like: vector<-c("BAKING CO", "NEW COBALT", "CO INC") I would like to convert the word "CO" to "COMPANY", but only ...
James Rider's user avatar
1 vote
2 answers
75 views

Replace ordinal numbers in R?

In R, suppose I have a string vector composed of words: string1<-c("1ST COMPANY", "21ST LIBRARY") However, within these strings, I want to convert ordinal number words like &...
James Rider's user avatar
4 votes
3 answers
82 views

How to extract birth and death year from string in R?

I have the first paragraph of Wikipedia articles from the wikifacts package (only for people). I like to extract birth year and year of death. library(wikifacts) library(tidyverse) politicians <- ...
Marco's user avatar
  • 2,727
3 votes
2 answers
86 views

Combining singleton letters?

I have the following character vector: vec1 <- c("D R JOHNSON", "NICE W E A T H E R") This vector has consecutive series of single letters like "D R" which I do NOT ...
James Rider's user avatar
0 votes
2 answers
25 views

splitting string into new columns different criteria in R

I have 2 different nomenclatures and want to split the patient ID and timepoint Original dataframe patient_id_and_timepoint 12345 V1 101-123-V1 Desired dataframe patient_id timepoint 12345 V1 ...
lovebead33's user avatar
1 vote
3 answers
60 views

how to search column for multiple strings in R

I have a list of characters and I would like to search for them and a create a column for them in R. antifungals <- c("caspofungin", "fluconazole") Here is an example: Original ...
lovebead33's user avatar
0 votes
1 answer
28 views

How to insert characters after a pattern using stringr?

I have a character vector xx <- c ("AB", "BA", "CA") I would like to insert the word "hello" after the first element, but only if this element is not A. I ...
Pavel Shliaha's user avatar
1 vote
2 answers
44 views

What is the correct syntax for specifying length for positive look behind?

I have a series of expressions that start with numbers of different length and I would like to extract the string after these numbers: e.g. c("14ac", "148me3") I would like to get ...
Pavel Shliaha's user avatar
1 vote
4 answers
86 views

What is the most elegent way to insert characters (passed on as a vector) at a certain position in the string (passed on as vector) using stringr?

I need to insert the following characters: c("me3", "ac") in positions c(1, 6) in the following string KSTGGKAPR. What is the most elegant way to do this? Can I avoid writing a ...
Pavel Shliaha's user avatar
2 votes
1 answer
64 views

Extract *all* possible patterns in a variable

I have a large variable containing strings (words). I need to extract all substrings that contain any of the patters listed in a separate vector. library(tidyverse) df <- data.frame(Word = c("...
RobertP.'s user avatar
  • 285

15 30 50 per page
1
2 3 4 5
173