This rough approach uses dplyr in R, but could be adapted for a different tool: group_by(userID, post_pagename) %>%filter(!is.na(post_pagename) %>%arrange(hit_time_gmt) %>%mutate(pageViewNum = 1,pageViewNum = cumsum(pageViewNum),firstVisitToPage = ifelse(pageViewNum == 1, 1, 0)) %>%ungroup()Group by...