controws | R Documentation |
This function extracts specific rows from a data frame along with their context, based on a given range. It can take either a vector of row numbers or a boolean vector as input. Additionally, the function allows specifying the direction of the context (above, below, or both) and marks each row as either targeted or context.
controws(data, input, context = 1, direction = "both")
data |
A data frame from which rows and their context will be extracted. |
input |
A numeric vector of row numbers or a logical vector. If a logical vector is given, the function will extract rows where the vector is TRUE. |
context |
An integer specifying the number of rows above and/or below the target row to include as context. Default is 1. |
direction |
A character string specifying the direction of context to include. Valid options are "up" for rows above, "down" for rows below, and "both" for both directions. Default is "both". |
A dataframe containing the targeted rows and their contextual rows. An additional column '.RowType' indicates whether it is a row given as input ("->") or part of the context ("").
# Example dataframe
data <- data.frame(matrix(rnorm(100), ncol = 5))
# Get context for rows 8 and 15 (using row numbers)
result <- controws(data, c(8, 15), 1, "both")
result
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.