[R] Derive pattern from vector
syrvn
mentor_ at gmx.net
Sat Feb 11 18:11:12 CET 2012
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.
More information about the R-help
mailing list