gsub Questions

3

Solved

Assume 900+ company names pasted together to form a regex pattern using the pipe separator -- "firm.pat". firm.pat <- str_c(firms$firm, collapse = "|") With a data frame called "bio" that has...
Palomo asked 23/2, 2015 at 22:8

6

Solved

I have a string in a variable which we call v1. This string states picture numbers and takes the form of "Pic 27 + 28". I want to extract the first number and store it in a new variable called item...
Geranial asked 27/4, 2014 at 12:21

3

Solved

I am reading in a bunch of CSVs that have stuff like "sales - thousands" in the title and come into R as "sales...thousands". I'd like to use a regular expression (or other simp...
Stefa asked 23/9, 2016 at 23:26

3

Solved

I have a string vec = c('blue','red','flower','bee') I want to convert different strings into the same in one line instead of seperately i.e. i could gsub blue and gsub red to make them both spe...
Aflcio asked 2/2, 2015 at 19:42

8

Solved

I'm using the gsub function in R to return occurrences of my pattern (reference numbers) on a list of text. This works great unless no match is found, in which case I get the entire string back, in...
Tifanytiff asked 18/4, 2012 at 17:23

8

Solved

I would like to remove specific characters from strings within a vector, similar to the Find and Replace feature in Excel. Here are the data I start with: group <- data.frame(c("12357e", "125...
Mammillate asked 13/8, 2012 at 14:26

4

Solved

I want to replace dots in "2014.06.09" to "2014-06-09". I am using gsub() function for it. If x <- "2014.06.09" gsub('2', '-' ,x) # [1] "-014.06.09" But when I try gsub('.', '-', x) # [1] ...
Aplenty asked 20/7, 2015 at 13:45

4

Solved

I am trying to apply gsub in R to replace a match in string a with the corresponding match in string b. For example: a <- c("don't", "i'm", "he'd") b <- c("do not", "i am", "he would") c &lt...
Subdeacon asked 2/4, 2015 at 0:19

10

Solved

I have a string variable containing alphabet [a-z], space [ ], and apostrophe ['], e.g. x <- "a'b c" I want to replace apostrophe ['] with blank [], and replace space [ ] with undersco...
Emilia asked 27/11, 2015 at 3:44

4

Solved

I'm trying to extract the number of times a given character is repeated and use it in the string to replace it for. Here's an example : before = c("w","www","answer",&...
Billyebilobate asked 25/4, 2023 at 9:41

4

Solved

I've seen many iterations of extracting w/ gsub but they mostly deal with extracting from left to right or after one occurrence. I am wanting to match from right to left, counting four occurrences ...
Kellene asked 3/11, 2017 at 16:22

1

Solved

I know we are able to do it using other non-regex ways more efficiently, e.g., rev + strsplit or rev + substring, but I wonder if we can accomplish it with regex only. For example, assuming we hav...
Counterproof asked 26/9, 2022 at 9:21

5

I read a file: local logfile = io.open("log.txt", "r") data = logfile:read("*a") print(data) output: ... "(\.)\n(\w)", r"\1 \2" "\n[^\t]", "", x, re.S ... Yes, logfile looks awful as it's ful...
Moribund asked 20/3, 2012 at 16:18

2

Solved

I have a matrix that contains the string "Energy per �m". Before the 'm' is a diamond shaped symbol with a question mark in it - I don't know what it is. I have tried to get rid of it by using t...
Reparable asked 15/8, 2012 at 14:12

3

I have following string vector: EC02 502R 603 515 602 KL07 601 511R 505R 506R 503 508 514 501 509R 510 501R 512R 516 507 604 502 601R SPK01 504 504R ACK01 503R 508R 507R ACK03 513 EC01...
Scuta asked 24/7, 2017 at 3:10

5

Solved

I have downloaded the street abbreviations from USPS. Here is the data: dput(usps_streets) structure(list(common_abbrev = c("allee", "alley", "ally", "aly", ...
Kymberlykymograph asked 6/10, 2021 at 14:29

6

Solved

I have a strings that look like this: problem <- c("GROUP 1", "GROUP 1 & GROUP 2", "GROUP 1 & GROUP 2 & GROUP 3", "GROUP 1 & GROUP 2 & GROU...
Stomatology asked 8/10, 2021 at 18:37

5

Solved

I would like to remove everything after a space in a string. For example: "my string is sad" should return "my" I've been trying to figure out how to do this using sub/gsub but have been u...
Pilcomayo asked 16/2, 2012 at 21:20

3

Solved

I am looking for regex (preferably in R) which can replace (any number of) specific characters say ; with say ;; but only when not present inside parenthesis () inside the text string. Note: 1. The...
Georgiegeorgina asked 8/6, 2021 at 11:52

5

Solved

I would like to shorten the values of one column of my data.frame. Right now, each value consists of many letters, such as df$col1 [1] AHG ALK OPH BCZ LKH QRQ AAA VYY what I need is only the fi...
Federalism asked 11/3, 2015 at 10:45

4

Solved

How do you limit the number of replacements made by String#gsub in Ruby? In PHP this can be easy done with preg_replace which takes a parameter for limiting replacements, but I can't figure out ho...
Tuneless asked 15/5, 2011 at 16:20

3

I am trying to remove a parenthesis from a string in R and run into the following error: string <- "log(M)" gsub("log", "", string) # Works just fine gsub("log(", "", string) #breaks # Error in...
Eschatology asked 26/2, 2012 at 0:34

3

Solved

I have a string that I am trying to work with in using the gsub method in Ruby. The problem is that I have a dynamic array of strings that I need to iterate through to search the original text for ...
Nudi asked 1/11, 2010 at 2:38

2

Solved

I have a field of strings in a data frame all similar to: "Young Adult – 8-9"" where the inner single " is what I want to replace with nothing to get: "Young Adult - 8-9&...
Sanitarian asked 17/5, 2016 at 17:16

4

Solved

I have a data frame like this: name weight r apple 0.5 y pear 0.4 y cherry 0.1 g watermelon 5.0 pp grape 0.5 y apple pear 0.4 ... ... I would like to remove all characters before the first white...
Tamworth asked 24/9, 2015 at 17:8

© 2022 - 2025 — McMap. All rights reserved.