Hello, consider the following vector 'chars':
chars <- c(A, B, C, C, D, E, E, E, F, F, F) I need to convert 'chars' into the following pattern: 1, 2, 3, 3, 4, 5, 5, 5, 6, 7, 8 As soon as there are duplicates they get the same number otherwise it's increasing numbers. However, for the char 'F' it should be always increasing numbers. Is that possible in R? I used the following code: chars <- c('A', 'B', 'C', 'C', 'D', 'E', 'E', 'E', 'F', 'F', 'F') chars_dup <- duplicated(chars) cumsum(!chars_dup) [1] 1 2 3 3 4 5 5 5 6 6 6 But I do not know how to treat 'F' in the way described above. Regards -- View this message in context: http://r.789695.n4.nabble.com/Derive-pattern-from-vector-tp4379312p4379312.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.