How to change row names of a particular column in the same way in R

I am new in R and I have a very basic question.

MY ID column in my data frame is like this:

ID 
100-01
101-01
500-01
499-01 
.
.

And I want to convert those "-01" to "-02". How can I do that?

Thanks a lot!

>Solution :

You can use sub

  df$ID <- sub("-01", "-02", df$ID)
  df
      ID
1 100-02
2 101-02
3 500-02
4 499-02

Leave a Reply