pivot_table | R Documentation |
Create a pivot table
pivot_table(
data,
rows,
cols = NULL,
wt = NULL,
stats = c("n", "p", "p_row", "p_col"),
digits = 2,
total = TRUE,
total_label = "Total",
na_label = "<missing>",
complete = TRUE
)
data |
a |
rows |
Character vector of variable(s) to use as rows. |
cols |
Character vector of variable(s) to use as columns. |
wt |
Character, variable to use as weights if any. |
stats |
Statistic(s) to compute. |
digits |
Integer indicating the number of decimal places to be used. |
total |
Logical, add total or not. |
total_label |
Label to use fo total. |
na_label |
Label to use for missing values. |
complete |
Complete missing combination between
|
a data.table
library(flexpivot)
data("nobel_laureates")
# One variable
pivot_table(nobel_laureates, rows = "category")
# With two variables
pivot_table(nobel_laureates, rows = "category", cols = "birth_continent")
# Only count
pivot_table(nobel_laureates, rows = "category", cols = "gender", stats = "n")
# Only percent
pivot_table(nobel_laureates, rows = "category", cols = "gender", stats = "p")
# Without total
pivot_table(nobel_laureates, rows = "category", cols = "gender", total = FALSE)
# Two variable as rows
pivot_table(nobel_laureates, rows = c("birth_continent", "category"), cols = "gender")
# Two variable as cols
pivot_table(nobel_laureates, rows = "category", cols = c("gender", "laureate_type"))
# Round
pivot_table(nobel_laureates, rows = "category", digits = 0)
# Without cols
pivot_table(nobel_laureates, rows = "category")
pivot_table(nobel_laureates, rows = c("category", "birth_continent"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.