Hi, You could use:
res<-unsplit(lapply(split(Vec,Vec),function(x) if(length(x)>1) c(head(x,1),paste0(head(x,-1),seq_along(head(x,-1)))) else x),Vec) res # [1] "B" "B1" "C" "E" "B2" "E1" "E2" "D" "D1" "A" A.K. ----- Original Message ----- From: Christofer Bogaso <bogaso.christo...@gmail.com> To: r-help <r-help@r-project.org> Cc: Sent: Monday, March 4, 2013 2:13 PM Subject: [R] A problem with text manipulation Hello again, Let say I have following vector: set.seed(1) Vec <- sample(LETTERS[1:5], 10, replace = TRUE) Vec Now with each repeated letter, I like to add suffix programatically. Therefore I want to get following vector: c("B", "B1", "C", "E", "B2", "E1", "E2", "D", "D1", "A") Can somebody tell me how to achieve that? Thanks and regards, ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.