Add equations to 19.2 Ex 4. (#749)

The question asks:

> Follow <http://nicercode.github.io/intro/writing-functions.html> to write your own functions to compute the variance and skew of a numeric vector.

However, the math on that page no longer renders.

Directly include the skew and variance equations in the question.
This commit is contained in:
Jeffrey Arnold 2020-01-15 10:41:22 -08:00 committed by Hadley Wickham
parent 6194b380c4
commit 5082dd8bfd
1 changed files with 10 additions and 3 deletions

View File

@ -150,9 +150,16 @@ This is an important part of the "do not repeat yourself" (or DRY) principle. Th
sd(x, na.rm = TRUE) / mean(x, na.rm = TRUE)
```
1. Follow <http://nicercode.github.io/intro/writing-functions.html> to
write your own functions to compute the variance and skew of a numeric
vector.
1. write your own functions to compute the variance and skewness of a numeric vector.
Variance is defined as
$$
\mathrm{Var}(x) = \frac{1}{n - 1} \sum_{i=1}^n (x_i - \bar{x}) ^2 \text{,}
$$
where $\bar{x} = (\sum_i^n x_i) / n$ is the sample mean.
Skewness is defined as
$$
\mathrm{Skew}(x) = \frac{\frac{1}{n-2}\left(\sum_{i=1}^n(x_i - \bar x)^3\right)}{\mathrm{Var}(x)^{3/2}} \text{.}
$$
1. Write `both_na()`, a function that takes two vectors of the same length
and returns the number of positions that have an `NA` in both vectors.