R/reginfotable.R

Defines functions reginfotable

Documented in reginfotable

utils::globalVariables(c("key", "stat", ".", "name"))

#' @title Make table of regression statistics
#'
#' @name reginfotable
#' @param reginfo list of regression statistics extracted by .reginfo function
#'
#' @return data.frame of regression statistics
#' @export

reginfotable <- function(reginfo) {

  stats.list <- data.frame(
    key = c("rsq", "adj.rsq", "f", "n"),
    name = c("R2", "Adjusted R2", "F-stat", "N"),
    stringsAsFactors =  FALSE
  )

  keep <- reginfo %>%
    list.map(as.matrix(.[["list"]])) %>% list.cases()

  var_name <- stats.list %>% filter(key %in% keep)

  res <- suppressWarnings(
    reginfo %>%
      list.map(
        .[["value"]] %>%
          right_join(var_name, by = "key") %>%
          select(stat)
      ) %>%
      list.cbind()
  )

  tab <- var_name %>% select(name) %>% cbind(., res)
  rownames(tab) <- NULL

  return(tab)

}
KatoPachi/FlextableLikeStar documentation built on April 11, 2020, 11:43 a.m.