Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove first character from a string

Tags:

regex

r

Is there a way to remove or replace with "", the "X" from the beginning of words?

Ex:

XN5634_er
X123_er
NX45

Desired output:

N5634_er
123_er
NX45

Totally I have about 14.000 words. I used

gsub("X", '', mylist, fixed = T)     

but X is removed from NX45 too.

like image 570
Fuv8 Avatar asked Jan 15 '14 13:01

Fuv8


Video Answer


1 Answers

Try:

> mylist <- list("XN5634_er", "X123_er", "NX45")
> gsub("^X", '', mylist)
[1] "N5634_er" "123_er"   "NX45" 
like image 200
user1981275 Avatar answered Sep 21 '22 23:09

user1981275