R/list2d_to_df.R

Defines functions list2d_to_df

Documented in list2d_to_df

#' Convert a list of lists to a dataframe
#'
#' @export
list2d_to_df <- function(lol, colname) {
  lol %<>%
    t %>% as.data.frame %>%
    dplyr::mutate_(.dots = setNames(list(~ row.names(.)), colname))
  lol[] <- lapply(lol, unlist)
  lol
}

# vapply(letters[1:3], function(x){list(a=5, b="ff", c=x)}, list(0, "", "")) %>%
# list2d_to_df("lettername")
daattali/rsalad documentation built on Oct. 28, 2019, 12:16 p.m.