tidy_df: Generate a data.frame using a ggplot2-like interface

Description Usage Arguments Details Value See Also Examples

View source: R/tidy_df.R

Description

Builds a data.frame by mapping columns from the input data, x, to elements of an htmlTable (e.g. rnames, header, etc.).

Usage

1
2
3
4
tidy_df(x, value = "value", header = "header", rnames = "rnames",
  rgroup = NULL, cgroup1 = NULL, cgroup2 = NULL, tspanner = NULL,
  hidden_rgroup = NULL, hidden_cgroup1 = NULL, hidden_cgroup2 = NULL,
  hidden_tspanner = NULL, collapse = NULL, ...)

Arguments

x

A tidy data.frame

value

Column in x specifying values used to populate individual cells of the output table

header

Column in x specifying column headings

rnames

Column in x specifying row names

rgroup

Column in x specifying row groups

cgroup1

Column in x specifying the inner most column groups

cgroup2

Column in x specifying the outer most column groups

tspanner

Column in x specifying tspanner groups

hidden_rgroup

rgroup values that will be hidden.

hidden_cgroup1

cgroup1 values that will be hidden.

hidden_cgroup2

cgroup2 values that will be hidden.

hidden_tspanner

tspanner values that will be hidden.

collapse

Character used to separate combinations of cgroups and rnames/rgroups/tspanners. If set to NULL, then row and column names will be expanded to into extra rows and columns on the upper and left borders of the table respectively.

...

Additional arguments that will be passed to the inner htmlTable function

Details

The tidy_df function is designed to work like ggplot2 in that columns from x are mapped to specific parameters from the htmlTable function in the htmlTable package, similar to tidy_htmlTable. However, instead of outputting html code, tidy_df constructs a data.frame, making it easier to export output to a .csv or other tabular file.

Value

Returns a data.frame

See Also

tidy_htmlTable

htmlTable

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 
library(tidyverse)
mtcars %>%
    rownames_to_column %>%
    select(rowname, cyl, gear, hp, mpg, qsec) %>%
    gather(per_metric, value, hp, mpg, qsec) %>%
    group_by(cyl, gear, per_metric) %>%
    summarise(Mean = round(mean(value), 1),
              SD = round(sd(value), 1),
              Min = round(min(value), 1),
              Max = round(max(value), 1)) %>%
     gather(summary_stat, value, Mean, SD, Min, Max) %>%
     ungroup %>%
     mutate(gear = paste(gear, "Gears"),
            cyl = paste(cyl, "Cylinders")) %>%
     tidy_df(header = "gear",
            cgroup1 = "cyl",
            cell_value = "value",
            rnames = "summary_stat",
            rgroup = "per_metric")

## End(Not run)

graggsd/tidytableR documentation built on June 26, 2018, 4:28 p.m.