aboutsummaryrefslogtreecommitdiff
path: root/R/mkin_wide_to_long.R
blob: 21ab77b93997fce6e927f780ad0dc99b948af557 (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)
  if (!(time %in% colnames)) stop("The data in wide format have to contain a variable named ", time, ".")
  vars <- subset(colnames, colnames != time)
  n <- length(colnames) - 1
  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