R/bootstrap.R

Defines functions sample_boot

Documented in sample_boot

#' Variable bootstrap
#'
#' @param table a dataframe or matrix
#' @param matrix logical
#' @param col integer. The column to keep
#'
#' @return A table.
#' @export
#'
#' @examples
#' sample_boot(swiss)
sample_boot <- function(table, matrix = FALSE, col = 1){

  if(col == 0 | matrix){
    newcol <- sample(ncol(table), replace = TRUE)
  } else {
    newcol <- c(col, sample(seq_along(table)[-col], replace = TRUE))
  }

  return(table[, newcol])
}
abichat/correlationtree documentation built on March 11, 2020, 3:55 p.m.