Learn R Programming

tidyfst (version 0.7.7)

wider_dt: Pivot data from long to wide

Description

Analogous function for pivot_wider in tidyr.

Usage

wider_dt(
  data,
  group_to_keep = NULL,
  name_to_spread,
  value_to_spread = NULL,
  fill = NA
)

Arguments

data

data.table

group_to_keep

The unchanged group in the transformation. Could use integer vector, character vector or regular expression(to match the column names). If NULL, use all other variables.

name_to_spread

Chracter.One column name of class to spread

value_to_spread

Chracter.One column name of value to spread. If NULL, use all other variables.

fill

Value with which to fill missing cells. Default uses NA.

Value

data.table

See Also

dcast

pivot_wider

Examples

Run this code
# NOT RUN {
 stocks = data.frame(
   time = as.Date('2009-01-01') + 0:9,
   X = rnorm(10, 0, 1),
   Y = rnorm(10, 0, 2),
   Z = rnorm(10, 0, 4)
 ) %>%
   longer_dt(time) -> longer_stocks

 longer_stocks

 longer_stocks %>%
   wider_dt("time","variable","value")

 longer_stocks %>%
   mutate_dt(one = 1) %>%
   wider_dt("time","variable","one")

# }

Run the code above in your browser using DataLab