R/as.data.frame.hash.R

Defines functions as.data.frame.hash

Documented in as.data.frame.hash

#' Turn a hash into a data.frame
#'
#' Transform a hash into a nrowx2 data.frame
#'  
#' @param x hash
#' @param key string; name for the column of keys (Default: "key").
#' @param value string; name for the column of values (Default: "value")
#' @param ... additional arguments to [values()]
#'  
#' @return 
#' a data.frame with as many row as elements in `x` and two columns one for the
#' keys (always character) and value a list column
#'      
#'                
#' @examples 
#' 
#'  h <- hash( a=1, b=1:2, c=1:3)
#'  as.data.frame(h)
#'  
#' @export

as.data.frame.hash <- function(x, ..., key="key", value="value" ) {
  df <- as.data.frame( list( keys(x) ), col.names=key )
  df[[value]] <- values(x)
  df 
}
decisionpatterns/r-hash documentation built on Feb. 6, 2019, 10:27 p.m.