R:更改列重复的名称

时间:2013-11-17 19:20:48

标签: r

我在一列中有一个包含许多重复值的数据集:

A
A
A
A
B
B
B
B

...  我怎样才能改变它:

A1
A2
A3
A4
B1
B2
B3
B4
…

由于

1 个答案:

答案 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"