Learn R Programming

R.AlphA.Home (version 2.0.2)

countSwitches: create an incremented Counter, based on Start/Stop Markers

Description

This function aims at identifying sections and sub-sections numbers, based on markers of section starts and ends.

Given a data frame, and the name of a column giving the start/stop markers, it will add columns giving infos about the successive section levels

Usage

countSwitches(
  data,
  colNm,
  sttMark,
  endMark,
  includeStt = TRUE,
  includeEnd = TRUE
)

Value

A modified version of the input data frame with additional columns including:

  • `catLvl`: The current series level calculated as the difference between the cumulative counts of start and end markers.

  • `lvl_1`, `lvl_2`, `lvl_3`: Final series counts returned for each respective level.

Arguments

data

A data frame containing the column to process.

colNm

A string specifying the column name in `data` to evaluate.

sttMark

A value indicating the start of a series.

endMark

A value indicating the end of a series.

includeStt

Logical. Should the start marker be included as part of the series? Default is `TRUE`.

includeEnd

Logical. Should the end marker be included as part of the series? Default is `TRUE`.

Examples

Run this code
# example code
library(dplyr)
tribble(
~step
, "start"
, "content of section 1"
, "start"
, "subsection 1.1"
, "end"
, "end"
, "out of any section"
, "start"
, "section 2"
, "start"
, "subsection 2.1"
, "end"
, "start"
, "subsection 2.2"
, "end"
, "end"
) %>%
	countSwitches(colNm = "step", "start", "end")

Run the code above in your browser using DataLab