Reshaping grouped data via melt to 'long' format. The responses are merged in one column, with its column name in an additional column. This column is split into multiple columns, if a split character is given. All predictors are merged multiple times corresponding to the number or responses.

reshapeLong(
  dataset = cs.in.dataset(),
  preds = cs.in.predictors(),
  resps = cs.in.responses(),
  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.

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 melt . Please consider possible script variables (scriptvars) to prevent duplicates.

Value

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

reshapeLong

Dataset with reshaped data.

Details

One script variables is summarized in scriptvars list:

split

[character(1)]
Split character to split response names into multiple columns. Default is “_”.

Examples

# Data to transform: library(data.table) dtTest = data.table(i_1 = c(1:4, NA, 5), i_2 = c(51, 61, NA , 71, 81, 91) , f1 = factor(sample(c(letters[1:3], NA), 6, TRUE)) , f2 = factor(c("z", "a", "x", "c", "x", "x"), ordered = TRUE) ) # Reshape to long format: reshapeLong(dtTest, c("i_1", "i_2"), c("f1", "f2"), list(split = "_"), return.results = TRUE)
#> $reshapeLong #> i_1 i_2 variable value #> 1: 1 51 f1 c #> 2: 2 61 f1 b #> 3: 3 NA f1 c #> 4: 4 71 f1 b #> 5: NA 81 f1 a #> 6: 5 91 f1 b #> 7: 1 51 f2 z #> 8: 2 61 f2 a #> 9: 3 NA f2 x #> 10: 4 71 f2 c #> 11: NA 81 f2 x #> 12: 5 91 f2 x #>