R/convert.R

#'@title Convert a list to a data.frame
#'@description takes a list and converts it into a data.frame - without
#'strings converting to factors.
#'
#'@param list the input list
#'
#'@param result_names the names for the columns of the resulting
#'data.frame.
#'
#'@export
list_to_df <- function(list, result_names){
  results <- data.frame(matrix(unlist(list), nrow = length(list), byrow = TRUE))
  names(results) <- result_names
  return(results)
}

#'@title convert variables in a data.frame to an aggregated matrix.
#'@description takes variables from a data.frame and generates
#'a matrix of the aggregated permutations; designed for running,
#'say, fisher tests against.
#'
#'@param ... data.frame variables.
#'
#'@export
df_vars_to_matrix <- function(...){
  matrix(x    = table(...),
         nrow = length(...))
}
Ironholds/olivr documentation built on May 7, 2019, 6:40 a.m.