0

While studying tidyverse, I found something cannot understand. The missing data should be excluded with using na.rm = TRUE , so that calculating 'mean' will return a particular value. However, some gropus reveal NaN instead of a number.

In library 'dplyr', we can use starwars dataset.

starwars |> group_by(species) |> summarise(across(where(is.numeric), mean, na.rm=T))

The results include NaN and I cannot find why this happened

  • 2
    Some groups have all NAs, to replicate this issue try: `mean(c(NA, NA, NA), na.rm = TRUE)` – zx8754 Jul 20 '23 at 08:15

0 Answers0