aboutsummaryrefslogtreecommitdiff
path: root/R/mkin_wide_to_long.R
blob: 6db2f33720b034bcd3ec56160d4150911257ad79 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
mkin_wide_to_long <- function(wide_data, time = "t")
{
  colnames <- names(wide_data)
  vars <- subset(colnames, colnames != time)
  n <- length(colnames) - 1
  if (!(time %in% colnames)) stop("The data in wide format have to contain a variable named ", time, ".")
  long_data <- data.frame(
    name = rep(vars, each = length(wide_data[[time]])),
    time = rep(wide_data[[time]], n),
    value = unlist(wide_data[vars]),
    row.names = NULL)
  return(long_data)
}

Contact - Imprint