data_long: Pivot data from wide to long

View source: R/data_long.R

data_longR Documentation

Pivot data from wide to long

Description

'data_long()' "lengthens" data, increasing the number of rows and decreasing the number of columns. The inverse transformation is [pivot_wider()].

Usage

data_long(
  data,
  cols = "group",
  names_to = "name",
  names_prefix = NULL,
  names_sep = NULL,
  names_pattern = NULL,
  values_to = "value",
  values_drop_na = FALSE,
  ...
)

Arguments

data

'data.frame'. The data to pivot.

cols

<['poor-select'][select_helpers]>. Columns to pivot into longer format.

values_to

'character(n)'. The name of the new column(s) that will contain the values of the pivoted variables.

...

Additional arguments passed on to methods.

Value

A 'data.frame'.

Examples

wide_data <- data.frame(replicate(5, rnorm(10)))
# Customizing the names
data_long(
  data = wide_data,
  cols = c(1, 2),
  names_to = "Column",
  values_to = "Numbers"
)


ZhonghuiGai/gfun documentation built on Feb. 10, 2023, 6:10 p.m.