wider_dt: Pivot data from long to wide

Description Usage Arguments Value See Also Examples

View source: R/long_wide.R View source: R/wider_dt.R

Description

Analogous function for pivot_wider in tidyr.

Usage

1
2
3
4
5
6
7
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
 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")

hope-data-science/tidydt documentation built on Feb. 21, 2020, 10:25 a.m.