diff --git a/missing-values.Rmd b/missing-values.Rmd index ad266d3..d872e59 100644 --- a/missing-values.Rmd +++ b/missing-values.Rmd @@ -221,6 +221,7 @@ health |> Summary functions generally work with zero-length vectors, but they may return results that are surprising at first glance. There's almost always some deeper logic behind them. + A sometimes simpler approach is to perform the summary and then make the implicit missings explicit with `complete()`. ```{r} @@ -237,3 +238,29 @@ health |> ``` Main con of this approach is that you need to carefully specify the `fill` argument so that + +## NaN + +Special not a number. +In general it behaves like an `NA`: + +```{r} +x <- c(NA, NaN) +is.na(x) +is.nan(x) +``` + +You get these from mathematical operations that don't have a well defined answer + +```{r} +0 / 0 +0 * Inf +Inf - Inf +sqrt(-1) +log(-1) +``` + +```{r} +sqrt(-1 + 0i) +log(-1 + 0i) +```