logicals.qmd: use if_else() in exercises instead of ifelse() (#1622)

This commit is contained in:
Floris Vanderhaeghe 2024-01-29 02:11:47 +01:00 committed by GitHub
parent aa5eaac43e
commit e56ccb6d94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -564,9 +564,9 @@ We don't expect you to memorize these rules, but they should become second natur
1. A number is even if it's divisible by two, which in R you can find out with `x %% 2 == 0`.
Use this fact and `if_else()` to determine whether each number between 0 and 20 is even or odd.
2. Given a vector of days like `x <- c("Monday", "Saturday", "Wednesday")`, use an `ifelse()` statement to label them as weekends or weekdays.
2. Given a vector of days like `x <- c("Monday", "Saturday", "Wednesday")`, use an `if_else()` statement to label them as weekends or weekdays.
3. Use `ifelse()` to compute the absolute value of a numeric vector called `x`.
3. Use `if_else()` to compute the absolute value of a numeric vector called `x`.
4. Write a `case_when()` statement that uses the `month` and `day` columns from `flights` to label a selection of important US holidays (e.g., New Years Day, 4th of July, Thanksgiving, and Christmas).
First create a logical column that is either `TRUE` or `FALSE`, and then create a character column that either gives the name of the holiday or is `NA`.