Skip to contents

Transforms a pivot table into a flat table (implemented by a tibble). An additional column with page information can be included. NA values can be excluded from the array of values.

Usage

unpivot(pt, include_page, na_rm, keep_col_names)

# S3 method for pivot_table
unpivot(pt, include_page = TRUE, na_rm = TRUE, keep_col_names = FALSE)

Arguments

pt

A pivot_table object.

include_page

A boolean, indicates whether a column with the page information is included or not.

na_rm

A boolean, indicates whether NA values from the array of values are removed or not.

keep_col_names

A boolean, if possible, keep the column names.

Value

A tibble.

Details

A pivot table should only contain label rows and columns, and an array of values, usually numeric data.

To correctly carry out this operation, the number of rows and columns that contain labels must be defined, and the table must only contain the pivot table rows and columns.

See also

Examples


a_tibble <-
  pt_ex |>
  remove_top(1) |>
  define_labels(n_col = 2, n_row = 2) |>
  unpivot(include_page = FALSE)

a_tibble <-
  pt_ex |>
  set_page(1, 1) |>
  remove_top(1) |>
  define_labels(n_col = 2, n_row = 2) |>
  remove_k() |>
  replace_dec() |>
  fill_values() |>
  fill_labels() |>
  remove_agg() |>
  unpivot()