Modify same values of a variable in R -


my data frame this:

name   no x      1 x      3 yyy    1 yyy    6 x      8 x      2 x      1 

i want change name of last 3 x not x (x1 example). same values not continuous must modified. there many cases in name variable. there way in r? quite not-sorted in sas.

thank much

rle suggests here "same values not continuous must modified"

r <- rle(as.character(df$name)) #run length encoding #  lengths: int [1:3] 2 2 3 #  values : chr [1:3] "x" "yyy" "x"  r$values <- make.unique(r$values,sep="") inverse.rle(r) #[1] "x"   "x"   "yyy" "yyy" "x1"  "x1"  "x1"  df$name <- inverse.rle(r) df  #  name no #1    x  1 #2    x  3 #3  yyy  1 #4  yyy  6 #5   x1  8 #6   x1  2 #7   x1  1