R/SDfunGen.R

#' A function which returns SD of input
#'
#' @description This is a daft little function that returns the SD of input.
#' @param x is input: vector, tibble or data frame
#' @param na.rm says whether to pass \code{na.rm} to \code{var()}. Defaults to TRUE.
#' @return SD if \code{var()} can compute the variance.
#' @keywords SD, "standard deviation"
#' @importFrom tibble is.tibble
#' @importFrom stats var
#' @export
#' @examples
#' SDfunGen(1:10)
SDfunGen <- function(x,na.rm=FALSE){
  ### funGen = function that can handle multiple forms of input including tibbles
  #require(tibble)
  if (!is.vector(x) & !tibble::is.tibble(x) & !is.data.frame(x)) stop("SDfunGen(x) needs vector input (or a numeric 1D tibble or data frame)!")
  if (is.tibble(x) | is.data.frame(x)) {
    x <- x[[1]]
  }
  if (!is.numeric(x)) stop("SDfunGen(x) needs numeric input")
  sqrt(var(x,na.rm = na.rm))
}
cpsyctc/CEFunctions documentation built on May 8, 2019, 11:11 p.m.