# NOT RUN {
# as_flextable and as_grouped_data -----
if( require("magrittr")){
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"))
zz <- as_flextable( data_co2 ) %>%
add_footer_lines("dataset CO2 has been used for this flextable") %>%
add_header_lines("mean of carbon dioxide uptake in grass plants") %>%
set_header_labels(conc = "Concentration") %>%
autofit() %>%
width(width = c(1, 1, 1))
zz
}
# }
Run the code above in your browser using DataLab