Skip to contents

Given .DF, find the row numbers that contain the first instance in col_name of adjacent entries, this function finds the row number of the adjacent entries.

Usage

adjacent_rownums(.DF, col_name, entries)

Arguments

.DF

the data frame in which to search for entries in col_name.

col_name

the column of .DF in which to search for consecutive entries.

entries

a vector of length 2 representing the consecutive entries in col_name for which to search.

Value

an integer vector of length 2 giving the rows for entries[[1]] and entries[[2]], whose difference is 1. NULL if no consecutive entries are found in col_name.

Details

This function is helpful for finding boundaries between rows of a data frame in preparation for defining grouping variables.

Examples

DF <- data.frame(C1 = c("A", "B", "C"))
DF %>% adjacent_rownums("C1", c("A", "B"))
#> [1] 1 2
DF %>% adjacent_rownums("C1", c("B", "C"))
#> [1] 2 3