Learn R Programming

flextable (version 0.9.11)

before: Detect rows before a given value

Description

Returns a logical vector indicating which elements of x appear before the first occurrence of any of the entries values. Useful as a row selector in hline() to insert a border above a summary row such as "Total".

Usage

before(x, entries)

Arguments

x

an atomic vector of values to be tested

entries

a sequence of items to be searched in x.

See Also

hline()

Examples

Run this code
library(flextable)
library(officer)

dat <- data.frame(
  stringsAsFactors = FALSE,
  check.names = FALSE,
  Level = c("setosa", "versicolor", "virginica", "", "Total"),
  Freq = as.integer(c(50, 50, 50, 0, 150)),
  `% Valid` = c(
    100 / 3,
    100 / 3, 100 / 3, NA, 100
  ),
  `% Valid Cum.` = c(100 / 3, 100 * 2 / 3, 100, NA, 100),
  `% Total` = c(
    100 / 3,
    100 / 3, 100 / 3, 0, 100
  ),
  `% Total Cum.` = c(
    100 / 3,
    100 * 2 / 3, 100, 100, 100
  )
)

ft <- flextable(dat)
ft <- hline(ft,
  i = ~ before(Level, "Total"),
  border = fp_border_default(width = 2)
)
ft

Run the code above in your browser using DataLab