我在一列中有一个包含许多重复值的数据集:
A
A
A
A
B
B
B
B
... 我怎样才能改变它:
A1
A2
A3
A4
B1
B2
B3
B4
…
由于
答案 0 :(得分:2)
您可以使用?ave
和?seq_along
:
b <- c("A","A","A","A","B","B","B","B","A","C")
ave(b, b, FUN=function(x)paste0(x, seq_along(x)))
# [1] "A1" "A2" "A3" "A4" "B1" "B2" "B3" "B4" "A5" "C1"