Fuv8
Fuv8

Reputation: 905

Remove first character from a string

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.

Upvotes: 6

Views: 3631

Answers (1)

user1981275
user1981275

Reputation: 13372

Try:

> mylist <- list("XN5634_er", "X123_er", "NX45")
> gsub("^X", '', mylist)
[1] "N5634_er" "123_er"   "NX45" 

Upvotes: 5

Related Questions