R/cols2list.R

Defines functions cols2list

Documented in cols2list

# cols2list.R
# ::rtemis::
# 2018 Efstathios D. Gennatas egenn.github.io

#' Convert data frame columns to list elements
#'
#' Convenience function to create a list out of data frame columns
#'
#' @param x Input: Will be coerced to data.frame, then each column will become an element of a list
#' @author Efstathios D. Gennatas
#' @export

cols2list <- function(x) {

  x <- as.data.frame(x)
  lst <- lapply(seq(x), function(i) x[, i])
  if (!is.null(colnames(x))) names(lst) <- colnames(x)
  lst

} # rtemis::cols2list
egenn/rtemis documentation built on March 25, 2020, 3:28 p.m.