From 5c78fb7ca5d8eef4b2faf189b29bb4698089db2c Mon Sep 17 00:00:00 2001 From: Mauro Lepore Date: Wed, 20 Jun 2018 03:58:54 -0400 Subject: [PATCH] Introduce `dplyr::case_when()` as an alternative to `ifelse()` (#587) Explain when ?dplyr::case_when() if more useful than ifelse. - Copy-pasted text from ?dplyr::case_when() --- EDA.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EDA.Rmd b/EDA.Rmd index cfb7cbf..8c934d4 100644 --- a/EDA.Rmd +++ b/EDA.Rmd @@ -247,7 +247,7 @@ If you've encountered unusual values in your dataset, and simply want to move on mutate(y = ifelse(y < 3 | y > 20, NA, y)) ``` -`ifelse()` has three arguments. The first argument `test` should be a logical vector. The result will contain the value of the second argument, `yes`, when `test` is `TRUE`, and the value of the third argument, `no`, when it is false. +`ifelse()` has three arguments. The first argument `test` should be a logical vector. The result will contain the value of the second argument, `yes`, when `test` is `TRUE`, and the value of the third argument, `no`, when it is false. Alternatively to ifelse, use `dplyr::case_when()`. `case_when()` is particularly useful inside mutate when you want to create a new variable that relies on a complex combination of existing variables. Like R, ggplot2 subscribes to the philosophy that missing values should never silently go missing. It's not obvious where you should plot missing values, so ggplot2 doesn't include them in the plot, but it does warn that they've been removed: