Skip to contents

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

Usage

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

Arguments

x

'grouped_data' object to be transformed into a "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

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

mean of carbon dioxide uptake in grass plants

Concentration

Quebec

Mississippi

Treatment: nonchilled

95

15.26667

11.30000

175

30.03333

20.20000

250

37.40000

27.53333

350

40.36667

29.90000

500

39.60000

30.60000

675

41.50000

30.53333

1,000

43.16667

31.60000

Treatment: chilled

95

12.86667

9.60000

175

24.13333

14.76667

250

34.46667

16.10000

350

35.80000

16.60000

500

36.66667

16.63333

675

37.50000

18.26667

1,000

40.83333

18.73333

dataset CO2 has been used for this flextable