R/se.R

Defines functions se

Documented in se

#' Calculate the standard error of the values in x.
#' If na.rm is TRUE then the missing values are removed before
#' calculating the error (default).
#'
#' @param x a numeric vector
#' @param na.rm logical. Should missing values be removed? Default na.rm = TRUE.
#'
#' @return a vector containing the width and height
#'
#' @examples
#' se(c(4,1,2,3,4))
#' @export

se = function(x, na.rm = TRUE) {

  if(!is.numeric(x)) warning("Provide numeric values.")
  N = length(x)

  if(any(is.na(x))) {
    N = N - sum(is.na(x))
    return(sd(x, na.rm=TRUE) / sqrt(N))
  }
  return(sd(x) / sqrt(N))
}
gnishihara/gnnlab documentation built on April 13, 2025, 5:48 p.m.