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()
This commit is contained in:
parent
528194c60d
commit
5c78fb7ca5
2
EDA.Rmd
2
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:
|
||||
|
||||
|
|
Loading…
Reference in New Issue