reshapeLong {CornerstoneR} | R Documentation |
Reshape Grouped Data to Long
Description
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.
Usage
reshapeLong(
dataset = cs.in.dataset(),
preds = cs.in.predictors(),
resps = cs.in.responses(),
scriptvars = cs.in.scriptvars(),
return.results = FALSE,
...
)
Arguments
dataset |
[ |
preds |
[ |
resps |
[ |
scriptvars |
[ |
return.results |
[ |
... |
[ANY] |
Details
One script variables is summarized in scriptvars
list:
- split
[
character(1)
]
Split character to split response names into multiple columns. Default is “_”.
Value
Logical [TRUE
] invisibly and outputs to Cornerstone or,
if return.results = TRUE
, list
of
resulting data.frame
object:
reshapeLong |
Dataset with reshaped data. |
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)