Suppose I have this dataframe, df, in R:
UserID <- c(1, 1, 1, 5, 5, 7, 7, 9, 9, 9)
PathID <- c(1,2,3,1,2,1,2,1,2,3)
Page <- c("home", "about", "services", "home", "pricing", "pricing", "home", "about", "home", "services")
df <- data.frame(UserID, PathID, Page)
I would like to add a column called "Set" which is an index of the combination of sequences.
So, my output should look like this:
UserID <- c(1, 1, 1, 5, 5, 7, 7, 9, 9, 9)
PathID <- c(1,2,3,1,2,1,2,1,2,3)
Page <- c("home", "about", "services", "home", "pricing", "pricing", "home", "about", "home", "services")
Set <- c(1,1,1,2,2,2,2,1,1,1)
df1 <- data.frame(UserID, PathID, Page, Set)
I would really appreciate some help here.