R/resample_df.r

#' Resample a Data Frame
#'
#' @param df : a data frame
#' @param size : a non-negative integer giving the number of items to choose.
#' @param replace : should sampling be with replacement?
#' @param prob : a vector of probability weights for obtaining the elements of the vector being sampled.
#'
#' @return a data frame containing the resampled rows.
#' @export
resample_df <- function(df, size, replace = FALSE, prob = NULL){
  sample_rows <- sample(1:nrow(df), size, replace, prob)
  return(df[sample_rows,])

}
ArithmeticR/TOmisc documentation built on May 14, 2019, 12:43 p.m.