Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pick mean fails with warning is not numeric #7629

Closed
kletts opened this issue Jan 23, 2025 · 1 comment
Closed

pick mean fails with warning is not numeric #7629

kletts opened this issue Jan 23, 2025 · 1 comment

Comments

@kletts
Copy link

kletts commented Jan 23, 2025

Just observed some strange behaviour when combining the dplyr::pick function with mean, which fails because of a is.numeric test in the base R function mean.

df <- tibble(
  x = c(3, 2, 2, 2, 1),
  y = c(0, 2, 1, 1, 4),
  z1 = c("a", "a", "a", "b", "a"),
  z2 = c("c", "d", "d", "a", "c")
)

Taking the sum is not an issue:

df %>% summarise(sum(pick(c(x,y))))

Taking the mean fails (returns only NA) with the warning:

df %>% summarise(mean(pick(c(x,y))))
# A tibble: 1 × 1
  `mean(pick(c(x, y)))`
                  <dbl>
1                    NA
Warning message:
There was 1 warning in `summarise()`.
ℹ In argument: `mean(pick(c(x, y)))`.
Caused by warning in `mean.default()`:
! argument is not numeric or logical: returning NA 

Thanks for a great package. Christian

@kletts
Copy link
Author

kletts commented Jan 23, 2025

I'll close this issue as I realised this doesn't have to do with pick, but my misunderstanding of how mean works: eg
df %>% summarise(mean(c(x,y))) works where df %>% summarise(mean(x,y)) doesn't.

@kletts kletts closed this as completed Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant