mark_first_in_each_group.Rd
Mark the first row in each group of rows.
mark_first_in_each_group(data, group_cols)
data | a data.frame ordered with respect to groups |
---|---|
group_cols | character names of the grouping columns |
numeric vector with index of first row in each group
d <- wrapr::build_frame( "g", "v" | 1 , 1L | 0 , 2L | 0 , 3L | 1 , 4L | 1 , 5L ) d <- d[wrapr::orderv(d), , drop = FALSE] d$fi <- mark_first_in_each_group(d, "g") print(d)#> g v fi #> 2 0 2 1 #> 3 0 3 1 #> 1 1 1 3 #> 4 1 4 3 #> 5 1 5 3