Most of the values in a variable of my dataset has two extra characters at the end to reprensent the number of visits from the subject, like id_0, or id_24, or id_48... Like in the below:
subjectid le lt
1 CC0005_0 4022.5 133.8
2 CC0196_0 4099.6 190.7
3 CC0197_0 5518.1 595.0
4 CC0202_48 6604.3 358.2
5 CC0212_0 7047.3 427.8
6 CC0239_24 4935.2 215.7
My first thought was to use apply and grepl together, but I couldn't go past:grepl("*_0", mydata$subjectid)
, this seems to catch the correct items, but how to rename them?
- How can I get rid of "_0" without changing the ones that have "_24" or "_48"?