R/long2mitml.list.R

Defines functions long2mitml.list

Documented in long2mitml.list

long2mitml.list <- function(x, split, exclude = NULL){
# convert data set in "long" format to mitml.list

  i1 <-  which(colnames(x) == split)
  f <- x[,i1]

  if(!is.null(exclude)){
    i2 <- if(length(exclude) == 1) f != exclude else !f %in% exclude
    x <- x[i2, , drop = F]
    f <- f[i2]
    if(is.factor(f)) f <- droplevels(f)
  }

  out <- split(x[, -i1, drop = F], f = f)
  names(out) <- NULL

  class(out) <- c("mitml.list", "list")
  return(out)

}

Try the mitml package in your browser

Any scripts or data that you put into this service are public.

mitml documentation built on Jan. 6, 2023, 5:17 p.m.