lundi 3 mai 2021

sub a pattern in a data frame in r except for when it includes another pattern

I have rows containing the following

temp1_01_100, temp2_01_100, temp2_02_100, s10_100, s11_100, s12_100, s21_100

I would like to replace the "_100" with "" e.g. doing that df$col <- sub("_100.*", "", df$col) but I don't want the replacement when there is the pattern "temp" no matter if it's temp1 or temp2.

Aucun commentaire:

Enregistrer un commentaire