I have two columns x
and y
, I am trying to create a new sequenced column z
if the value in one of the columns is non-unique. e.g.
x <- c("1", "1", "1", "1", "2", "2", "2", "3", "3", "3", "4", "4", "5", "6", "6", "6")
y <- c("Y", "Y", "Y", "Y", "N", "N", "Y", "Y", "Y", "Y", "Y", "Y", "Y", "N", "Y", "Y")
df <- data.frame(x, y)
What I would like to get is the following:
# x y z
#
# 1 Y 1
# 1 Y 2
# 1 Y 3
# 1 Y 4
# 2 N 1
# 2 N 2
# 2 Y 3
# 3 Y 1
# 3 Y 2
# 3 Y 3
# 4 Y 1
# 4 Y 2
# 5 Y 1
# 6 N 1
# 6 Y 2
# 6 Y 3