R/doUniqueCJ.R

Defines functions doUniqueCJ

Documented in doUniqueCJ

#' Performs a Cross Join of Unique combinations
#' 
#' This function makes use of \code{\link{CJ}} function of the data.table package to perform a
#' cross join. The function makes sure that the combinations are unique and removes NAs before
#' joining. doUniqueCJ is rather not used as a standalone function but inside \code{\link{computeShares}}. 
#' 
#' @author Matthias Bannert, Gabriel Bucur
#' @param dt data.table
#' @param cols character vector that denotes names of relevant columns
#' @export
doUniqueCJ <- function(dt, cols) {

unique_values <- lapply(cols, function(x) unique(na.omit(dt[[x]])))
names(unique_values) <- cols

do.call("CJ", unique_values)
}

Try the panelaggregation package in your browser

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

panelaggregation documentation built on May 2, 2019, 2:14 p.m.