R/std.R

Defines functions std_err std

Documented in std std_err

##
##  s t d . R
##


std <- function(x, flag=0) {
    if (length(x) == 0) return(c())
    if (!is.numeric(x))
        stop("Argument 'x' must be a numeric vector or matrix.")

    n <- if (flag == 0) length(x) - 1 else length(x)
    sqrt(sum((x-mean(x))*(x-mean(x)))/n)
}


std_err <- function(x) {
    if (length(x) == 0) return(c())
    if (!is.numeric(x))
        stop("Argument 'x' must be a numeric vector or matrix.")

    sqrt(var(x)/length(x))
}

Try the pracma package in your browser

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

pracma documentation built on March 19, 2024, 3:05 a.m.