produce a flextable from a table produced by function as_grouped_data().

# S3 method for grouped_data
as_flextable(x, col_keys = NULL, hide_grouplabel = FALSE, ...)

Arguments

x

object to be transformed as flextable

col_keys

columns names/keys to display. If some column names are not in the dataset, they will be added as blank columns by default.

hide_grouplabel

if TRUE, group label will not be rendered, only level/value will be rendered.

...

unused argument

Illustrations

See also

Examples

library(data.table) CO2 <- CO2 setDT(CO2) CO2$conc <- as.integer(CO2$conc) data_co2 <- dcast(CO2, Treatment + conc ~ Type, value.var = "uptake", fun.aggregate = mean) data_co2 <- as_grouped_data(x = data_co2, groups = c("Treatment")) ft <- as_flextable( data_co2 ) ft <- add_footer_lines(ft, "dataset CO2 has been used for this flextable") ft <- add_header_lines(ft, "mean of carbon dioxide uptake in grass plants") ft <- set_header_labels(ft, conc = "Concentration") ft <- autofit(ft) ft <- width(ft, width = c(1, 1, 1)) ft
#> a flextable object. #> col_keys: `conc`, `Quebec`, `Mississippi` #> header has 2 row(s) #> body has 16 row(s) #> original dataset sample: #> Treatment conc Quebec Mississippi #> 1 nonchilled NA NA NA #> 3 <NA> 95 15.26667 11.30000 #> 4 <NA> 175 30.03333 20.20000 #> 5 <NA> 250 37.40000 27.53333 #> 6 <NA> 350 40.36667 29.90000