R/sample_mean.R

Defines functions sample_mean

Documented in sample_mean

#' Takes a vector and from it takes a random sample of size n, then calculates sample mean
#'
#' @param vec A vector
#' @param n A number to represent the size of the sample
#'
#' @return A vector containing the sample mean.
#'
#' @import dplyr
#' @import purrr
#'
#' @export


sample_mean <- function(vec, n) {
  rsample <- map(n, ~sample(vec, .x, replace=TRUE))
  rsample_mean = map(rsample, ~mean(.x))
  sample_mean_vec = unlist(rsample_mean)

  return(sample_mean_vec)
}
reillynski/samplemeans documentation built on Aug. 9, 2020, 12:35 a.m.