r4ds-exercise-solutions icon indicating copy to clipboard operation
r4ds-exercise-solutions copied to clipboard

Exercise Exercise 5.7.6 wrong formula or description used

Open persep opened this issue 3 years ago • 0 comments

In Exercise 5.7.6 after the fisrt section of code it says

I add 1 to the denominator and numerator to avoid dividing by zero

But the code used only has 1 added to the denominator

standardized_flights <- flights %>%
  filter(!is.na(air_time)) %>%
  group_by(dest, origin) %>%
  mutate(
    air_time_mean = mean(air_time),
    air_time_sd = sd(air_time),
    n = n()
  ) %>%
  ungroup() %>%
  mutate(air_time_standard = (air_time - air_time_mean) / (air_time_sd + 1))

Anyway sd can never be zero for an object of length > 1

persep avatar Mar 07 '21 13:03 persep