R/dcast2.R

Defines functions dcast2

Documented in dcast2

#' Dcast using list columns
#'
#' @param data 
#' @param formula 
#' @param fun.aggregate 
#' @param sep 
#' @param ... 
#' @param margins 
#' @param subset 
#' @param fill 
#' @param drop 
#' @param value.var 
#' @param verbose 
#'
#' @return
#' @export
#'
#' @examples
dcast2 <- function(data, formula, fun.aggregate = NULL, sep = "_", ..., 
                   margins = NULL, subset = NULL, fill = NULL, drop = TRUE, 
                   value.var = data.table:::guess(data), verbose = getOption("datatable.verbose")){
  
  by_var <- all.vars(formula[-3])  # a vector with the names of the left hand terms
  
  data.table::dcast(data,
        formula,
        value.var = value.var,
        fun.aggregate = list)[,lapply(.SD,unlist),by_var]
}
dbrookeUAB/dth documentation built on Oct. 6, 2022, 10:52 p.m.