R/se.R

#' Standard Error Calculation
#'
#' This function calculates the standard error for a variable in a given data frame.
#' @importFrom gdata nobs
#' @importFrom stats qt sd
#' @param var variable to read in.
#' @param na.rm logical (default set to \code{T}). When set to \code{na.rm = F}, will include NA's in calculation.
#' @return This function returns the standard error for a given variable
#' @examples
#' data <- mtcars
#'
#' se(data$mpg)
#' @export


se <- function (var, na.rm = TRUE){
  stderror <- sd(var, na.rm = na.rm)/sqrt(nobs(var))
  if(na.rm == FALSE){
    stderror <- sd(var, na.rm = FALSE)/sqrt(nobs(var))
  }
  out <- stderror

  return(out)
}

Try the vannstats package in your browser

Any scripts or data that you put into this service are public.

vannstats documentation built on April 4, 2025, 1:37 a.m.