R/merge_cols.R

Defines functions merge_cols

merge_cols <- function(data, fun, ...) {
  # Helper function merge columns of matrix into one vector
  #
  # @param data data matrix
  # @param fun function to deal with different values per row
  # @param ... additional arguments to fun
  #
  # @return vector with combined columns
     
     data <- as.matrix(data)
     
     res <- apply(data, 1, function(xx) fun(unique(na.omit(xx)), ...))
     
     res[res == ""] <- NA

     res     
}

Try the TPP package in your browser

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

TPP documentation built on Nov. 8, 2020, 5:55 p.m.