Suppose you have a data frame like this:
test.df <- data.frame(
attribute_1 = c("A", "A", "A", "B", "B", "B")
, attribute_2 = c("i", "i", "j", "k", "k", "v")
)
attribute_1 attribute_2
1 A i
2 A i
3 A j
4 B k
5 B k
6 B v
Is there a simple / elegant way of creating an index (can be something as simple as an incrementing number) to assign an index to all rows with similar entries for attribute_1 and attribute_2
A desired output would be something like:
test.indexed.df <- data.frame(
attribute_1 = c("A", "A", "A", "B", "B", "B")
, attribute_2 = c("i", "i", "j", "k", "k", "v")
, index = c(1,1,2,3,3,4)
)
attribute_1 attribute_2 index
1 A i 1
2 A i 1
3 A j 2
4 B k 3
5 B k 3
6 B v 4
I already tried applying a checksum over these two columns but that seemed over the top.
Thanks in advance
Markus