I have a data frame (all_data) in which I have a list of sites (1... to n) and their scores e.g.
all_data
site score 1 10 1 11
Another way to do it. That I think is easy to get even when you know little about R:
library(dplyr) df <- data.frame('site' = c(1, 1, 1, 4, 4, 4, 8, 8, 8)) df <- mutate(df, 'number' = cumsum(site != lag(site, default=-1)))