Learn R Programming

psych (version 1.0-17)

# skew: Calculate skew for a vector, matrix, or data.frame

## Description

Find the skew for each variable in a data.frame or matrix. Unlike skew in e1071, this reports a different skew for each variable.

## Usage

`skew(x, na.rm = TRUE)`

## Arguments

x
A data.frame or matrix
na.rm
how to treat missing data

## Value

• if input is a matrix or data.frame, skew is a vector of skews

## Details

given a matrix or data.frame x, find the skew for each column.

`describe`

## Examples

Run this code
``````#round(skew(attitude),2)
## The function is currently defined as
function (x, na.rm = TRUE) {
if(length(dim(x))==0) {
if (na.rm)   { x <- x[!is.na(x)] }        #remove missing values
sum((x - mean(x))^3)/(length(x) * sd(x)^3)  #calculate skew  for a vector
} else { apply(x,2,function(x) sum((x - mean(x,na.rm=na.rm))^3,na.rm=na.rm)/( (length(x)-sum(is.na(x)) )* sd(x,na.rm=na.rm)^3)) }  }``````

Run the code above in your browser using DataLab