Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

reshapeWide

Reshape Grouped Data to Wide


Description

Reshaping grouped data via dcast to 'wide' format with rows for each unique combination of group variables. The response are arranged in separate columns for each datum in predictors. If a combination of groups identifies multiple rows, the number of rows in a group is returned to CS for the whole dataset instead of the response variable value.

Usage

reshapeWide(
  dataset = cs.in.dataset(),
  preds = cs.in.predictors(),
  resps = cs.in.responses(),
  groups = cs.in.groupvars(),
  auxs = cs.in.auxiliaries(),
  scriptvars = cs.in.scriptvars(),
  return.results = FALSE,
  ...
)

Arguments

dataset

[data.frame]
Dataset with named columns. The names correspond to predictors and responses.

preds

[character]
Character vector of predictor variables.

resps

[character]
Character vector of response variables.

groups

[character]
Character vector of group variables.

auxs

[character]
Character vector of auxiliary variables.

scriptvars

[list]
Named list of script variables set via the Cornerstone "Script Variables" menu. For details see below.

return.results

[logical(1)]
If FALSE the function returns TRUE invisibly. If TRUE, it returns a list of results. Default is FALSE.

...

[ANY]
Additional arguments to be passed to dcast . Please consider possible script variables (scriptvars) to prevent duplicates.

Details

One script variables is summarized in scriptvars list:

drop

[logical(1)]
Drop missing combinations (TRUE) or include all (FALSE). Default is TRUE.
For details see dcast.

Value

Logical [TRUE] invisibly and outputs to Cornerstone or, if return.results = TRUE, list of resulting data.frame object:

reshapeWide

Dataset with reshaped data.

Examples

# Reshape dataset to wide format:
reshapeWide(Indometh, "time", "conc", "Subject", character(0)
            , list(drop = TRUE, aggr.fun = "mean"), return.results = TRUE
            )

CornerstoneR

Collection of Scripts for Interface Between 'Cornerstone' and 'R'

v2.0.2
GPL-3
Authors
Gerrith Djaja [aut, cre], Dirk Surmann [aut] (<https://orcid.org/0000-0003-0873-137X>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.