How do you calculate mean, median, MAD and SD in R


  R Interview Questions

Let’s take a normal distribution.

> dist = rnorm(1000,mean=100,sd=10)
> plot(density(dist))

Mean

> mean(dist)
[1] 100.0442

Median

> median(dist)
[1] 100.0193

Mean Average Deviation

> mad(dist)
[1] 9.395154

Standard Deviation

> sd(dist)
[1] 9.87821

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.