# R/ds.skew.R In YRmisc: Y&R Miscellaneous R Functions

#### Documented in ds.skew

```###############################################################################################
##### Skewness
###############################################################################################

#' @name ds.skew
#' @aliases ds.skew
#' @title Calculating skewness for numeric data
#' @description Calculating Pearson's skewness in three types: mode, median, and mean.
#' @usage ds.skew(x, type = 3)
#' @param x :a numeric variable
#' @param type :type = 1 for mode skewness; type = 2 for median skewness; type = 3 for mean skewness
#' @examples ds.skew(mtcars[,1])

ds.skew <- function(x, type=3){
me <- mean(x,na.rm = T)
med <- median(x, na.rm = T)
mo <- ds.mode(x)
std <- sd(x,na.rm = T)
if(type == 1){
skewness <- (me-mo)/std
}else if(type == 2){
skewness <- 3*(me-med)/std
}else{
above <- mean((x - me)^3, na.rm = T)
below <- ((sum((x-me)^2, na.rm = T)/(length(x)-1))^(3/2))
skewness <- above/below
}
return(skewness)
}
```

## Try the YRmisc package in your browser

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

YRmisc documentation built on March 25, 2020, 5:13 p.m.