adjacent_rownums: Find row numbers for adjacent entries

View source: R/iea_splits.R

adjacent_rownumsR Documentation

Find row numbers for adjacent entries

Description

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.

Details

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

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.

Examples

DF <- data.frame(C1 = c("A", "B", "C"))
DF %>% adjacent_rownums("C1", c("A", "B"))
DF %>% adjacent_rownums("C1", c("B", "C"))

MatthewHeun/IEATools documentation built on Feb. 6, 2024, 3:29 p.m.