dcastSe: A standard-evaluation interface to 'data.table::dcast()

View source: R/dcastSe.R

dcastSeR Documentation

A standard-evaluation interface to 'data.table::dcast()

Description

data.table's dcast() transforms from long to wide format. It lacks a standard-evalutation interface for programming, and dcastSe() is an attempt to fill that gap, still using data.table::dcast() to perform the operation.

Usage

dcastSe(data, l, r, as.fun, ...)

Arguments

data

data set (data.frame) to transpose (widen).

l

left-hand side variables as character vector. Result will be long/vertical in these variables. The elements in 'l' can be named in which case the resulting columns will be renamed accordingly.

r

left-hand side variables as character vector. Result will be wide in these variables.

as.fun

An optional function to convert results with. If 'data' is a 'data.table', the default is to return a 'data.table', and if not the default is to return a 'data.frame'.

...

Additional arguments passed to 'data.table::dcast()'.

Details

Only two of l, r, and value.var are needed (see ?data.table::dcast for value.var), and the others will be derived. However, if value.var is a function, both l and r are needed.

Value

a data.frame (see argument 'as.fun')

Examples

dt <- data.frame(
  id = rep(1:3, each = 2),
  time = rep(c(0, 1), 3),
  value = 1:6
)
    
# Cast to wide format
dcastSe(dt, l = "id", r = "time", value.var = "value")
# rename a "left" column
dcastSe(dt, l = c(Subject="id"), r = "time", value.var = "value")

NMdata documentation built on June 17, 2026, 9:06 a.m.