Skip to contents

Create Flextable in The Mark USA Branding

Usage

test_flextable(data)

Arguments

data

Required, A tibble/data frame of summary/descriptice or test statistics.

Value

A nicely formatted table that is a flextable() object.

Examples

# Example data:
data <- dplyr::tibble(
  Organization = c(1, 2, 3, 4, 5, 4, 3, 2, 1),
  Source = c(2, 2, 3, 5, 4, 3, 2, 1, 2),
  Publish = c(1, 1, 1, 2, 2, 2, 3, 3, 3),
  Write = c(2, 2, 2, 3, 3, 3, 4, 4, 4),
  Research = c(1, 1, 2, 2, 3, 3, 4, 4, 4),
  group = factor(c(
      "grad", "undergrad", "grad", "undergrad", "grad",
      "undergrad", "undergrad", "grad", "undergrad"
                    ), levels = c("grad", "undergrad")
    )
)
# Summarise the data into mean and sd for each numeric column, grouped by "group":
data <- data %>% dplyr::group_by(group) %>%   dplyr::summarise(dplyr::across(
                                   .cols = dplyr::where(is.numeric),
                                   .fns =  list(Mean = mean, SD = sd),
                                   .names = "{col}_{fn}"
                                                  )) %>%
             dplyr::ungroup() %>%
             tidyr::pivot_longer(cols = -group,
                                 names_pattern = "([^_]+)_(.*)",
                                 names_to = c("variable", "stat"),
                                 values_to = "value",
                                 values_drop_na = TRUE) %>%
             tidyr::pivot_wider(names_from = stat, values_from = value)

# Make a nice table with the function:
data %>% test_flextable()

group

variable

Mean

SD

grad

Organization

2.75

1.7078251

grad

Source

2.50

1.2909944

grad

Publish

1.75

0.9574271

grad

Write

2.75

0.9574271

grad

Research

2.50

1.2909944

undergrad

Organization

2.80

1.3038405

undergrad

Source

2.80

1.3038405

undergrad

Publish

2.20

0.8366600

undergrad

Write

3.20

0.8366600

undergrad

Research

2.80

1.3038405