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
0
votes
0 answers

Problems in installing package stringr

I tried to install the package stringr but failed for several times. The error shows: library(stringr) Error: package or namespace load failed for ‘stringr’ in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object…
Jinggggggg
  • 21
  • 1
0
votes
1 answer

How to group columns together based on commonality in name, create a combined new column, eliminating NAs?

I have some data similar to this example data, where columns stand for years: data <- data.frame( X2020_1 = c("A", NA, "B"), X2020_2 = c("A", "C", NA), X2021_1 = c("A", NA, "C"), X2021_2 = c(NA, NA, "A") ) which looks like this: X2020_1…
ifoxfoot
  • 195
  • 7
0
votes
1 answer

file.copy: Trying to copy a batch of images into a different folder

I am currently trying to write a code that will read through a list of files, confirm it is an image, and then copy this file into its proper IMG folder. The setup of the directories currently has the images in a folder by month, and within this…
kelsiei
  • 3
  • 1
0
votes
1 answer

Replace column value by element of list from same column

I have the following dataframe. I applied the str_split() function to YEARS. library(dplyr) library(stringr) YEARS <- c("2020/2021", "2021/2022", "2022/2023") VALUE <- c(10,5,3) x <- data.frame(YEARS, VALUE) %>% …
axel
  • 15
  • 5
0
votes
1 answer

Extracting string after a hyphen with a variable number of characters

I have a character string with a hyphen, and I'd like to extract the characters, which happen to be numbers, after then hyphen; however, the number of characters after the hyphen can vary depending on an input I give. Sometimes the characters after…
EastBeast
  • 89
  • 7
0
votes
1 answer

use named vector to create column in pipe chain

In a pipe chain, I want to use a named vector to create a new column which matches the names of the vector with the string of a column: library(tidyverse) df <- data.frame(my_label = c("car", "house", "Bike", "ca"), xx = c(1, 2, 3,…
user63230
  • 4,095
  • 21
  • 43
0
votes
2 answers

Return all regex matches even when there is partial overlap in the matches

I have a regex pattern that looks for multiple words in a text and returns the match + (up to) five words that precede the match and the five words that follow the match. The problem is that if within this range of words the regex matches multiple…
Rasul89
  • 588
  • 2
  • 5
  • 14
0
votes
1 answer

How can I use R pdftools and stringr to extract the author's name from the first page of multiple PDF files?

I'm trying to extract a line of text from the first page of each multi-page PDF file in a list of PDFs. I'm trying to get the text into a dataframe so I can extract the author of each PDF, which is on the first page and the same word precedes the…
0
votes
2 answers

How do you parse a custom format string into columns of a R dataframe?

I am working with a dataframe that contains a column called stage that is in a custom string format. It seems to resemble JSON but isn't quite in that format. My initial thought was to try and convert it to JSON so then I could use some existing…
matt
  • 13
  • 3
0
votes
1 answer

Return any words beginning with space+ specified letters + a number

How can I return only words matching the pattern of beginning with a space + "t" or "r" directly followed by any number including negative numbers or decimals in R and returning NA where any of these conditions are not met? Edit including possible…
Neal Barsch
  • 2,810
  • 2
  • 13
  • 39
0
votes
1 answer

How to select the rows based in the counts in one column and group by anothe column

I have one data frame with several columns. I want to select only the rows that have especific information (species from one specific genus) that appear at least three times in the whole data frame and group by column "code". In the species columns…
pmp
  • 1
  • 2
0
votes
2 answers

how can I separate character versus digital with separate function

I have the below simple example library(tidyverse) dd = data.frame(xx=c("sdsds1234","ddd252","rrr34566")) dd %>% separate(col = xx,remove =F,into = c("Name","MedID")) xx Name MedID 1 sdsds1234 sdsds1234 2 ddd252 ddd252 …
Z. Zhang
  • 637
  • 4
  • 16
0
votes
1 answer

How to use str_split_fixed to split a column while removing the original column

I have a .txt file in following way Date/Time Temp [C] Pressure [P] 2006-01-01T00:00:00 25 1018 2006-01-01T00:01:00 25 1018 . . While reading it in R, the header and data appears as follows: Date.Time Temp..C. Pressur..P. [I dont know why…
0
votes
1 answer

How to read data stored in .txt file from a particular line in R?

I have multiple text files stored in different folders. The structure of data stored in each .txt file is the same. Each text file starts with some information and 5th line forward, the file has a sign */ after which data starts. The file appears as…
0
votes
1 answer

Keep the first 4 words in a column

I'm trying to only keep the first 4 words of a column in my data and still want to keep the other observations that have less than 4 words. This is a sample of what some of the data looks like. State Company Number of workers X FAIRFIELD…
bear_525
  • 41
  • 5
1 2 3
99
100