ps_5 error for getting mean in mtcars, REPREX

Wondering how to get this to work? I am trying to get the mean of number of gears for cars with less than 8 cylinders.

x <- mtcars %>% 
  filter(cyl < 8) %>% 
list(x) %>% 
#> Warning in mean.default(.): argument is not numeric or logical: returning NA
#> [1] NA

Created on 2020-03-18 by the reprex package (v0.3.0)

I think you want summarize() rather than count().

library(dplyr, warn.conflicts = FALSE)
#> Warning: package 'dplyr' was built under R version 3.6.3

mtcars %>%
  filter(cyl < 8) %>%
  summarize(mean_gear = mean(gear))
#>   mean_gear
#> 1         4

Created on 2020-03-19 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.