Description Usage Arguments Value Examples
View source: R/MultiWide2Long.R
Used for reshaping data more extensively than the reshape
,
melt
, or reshape2
functions available. Can reshape multiple
wide-format variables into long format.
1 2 | MultiWide2Long(data, idvars, varlist, timevals = 1:length(varlist[[1]]),
timevar = "time")
|
data |
A data frame that is wide format. |
idvars |
The id variable(s) that identify multiple records from the same unit. |
varlist |
A list of length equal to the number of variables to be reshaped from wide to long. The names of the elements will make up the names of the new long-format variables. Each element of the list is a character vector that contains the variable names in data that are to be reshaped. All elements must have character vectors of the same length. |
timevals |
A vector of numbers to use for time. Length must be equal to the size of the elements in varlist. Can be NA for no time. |
timevar |
A character containing the name of the new time variable. Can be NA for default name or no name if timevar is NA. |
A data frome in long format
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | summary(Indometh)
wide <- reshape(Indometh, v.names = "conc", idvar = "Subject",
timevar = "time", direction = "wide")
#add additional column so reshape has same size for two variables
wide$conc.9 = runif(n = 6, min = 0, max = .05)
wide
long <- MultiWide2Long(data = wide, idvars = "Subject",
varlist =
list(ConcLE2 =
c("conc.0.25",
"conc.0.5",
"conc.0.75",
"conc.1",
"conc.1.25",
"conc.2"),
ConcGT2 =
c("conc.3",
"conc.4",
"conc.5",
"conc.6",
"conc.8",
"conc.9")),
timevals = 1:6, timevar = "time")
long
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.