Reputation: 599
I have a dataframe with column that has numbers. I need to delete first 2 characters in some cases & first characters for some of them.
DF$code
Code
1-731-770-3820
(464)424
217-008
Here , from first record i need to delete 1-. from second record i need to delete (. Third record is good.
Output should be
Code
731-770-3820
464)424
217-008
I have 50000+ such mixed records. I was trying using gsub , but its deleting first character from the records which are already in good shape.
Thanks
Upvotes: 1
Views: 105
Reputation: 887971
We can use sub
DF$Code <- sub("^(1-|\\()", "", DF$Code)
DF$Code
#[1] "731-770-3820" "464)424" "217-008"
Upvotes: 2