Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use gsub remove all string before first numeric character

Tags:

string

r

gsub

Use gsub remove all string before first white space in R

In this example, we try to remove everything before a space with sub(".*? (.+)", "\\1", D$name). I'm looking for something really similar but I'm not really familiar with regex.

I want to delete everything before the first numeric character but without remove it

For example with:

x <- c("lala65lolo","papa3hihi","george365meumeu")

I want:

> "65lolo","3hihi", "365memeu"
like image 473
user3083101 Avatar asked Jan 22 '19 15:01

user3083101


1 Answers

In R 3.6 (currently the R devel version) onwards trimws has a new whitespace argument which can be used to specify what is regarded as whitespace -- in this case any non-digit character:

trimws(x, "left", "\\D")
## [1] "65lolo"    "3hihi"     "365meumeu"
like image 98
G. Grothendieck Avatar answered Sep 18 '22 11:09

G. Grothendieck