View source: R/countSwitches.R
countSwitches | R Documentation |
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
countSwitches(
data,
colNm,
sttMark,
endMark,
includeStt = TRUE,
includeEnd = TRUE
)
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'. |
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.
This function is currently mostly useful internally, to perform foldAllBr().
# 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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.