Problems with calling vectors in pipes

Hi there!

I was wondering if anybody has run into the same issue as me. Since I upgraded R studio, I can't call vectors anymore by using pipes in the count function.
For instance, count(df$vector) works, but using df %>% count(vector) returns the error: object 'vector' not found.
Other functions do seem to work using pipes.

Anyone who knows what's going on and how to fix it?

Strange, your results seem to be the opposite of the documentation for count():

count(x, ..., wt = NULL, sort = FALSE, name = NULL), where x is a data frame and ... are the variables to group by.

library(tidyverse)

count(mtcars, cyl)
#>   cyl  n
#> 1   4 11
#> 2   6  7
#> 3   8 14

mtcars %>% count(cyl)
#>   cyl  n
#> 1   4 11
#> 2   6  7
#> 3   8 14

mtcars |> count(cyl)
#>   cyl  n
#> 1   4 11
#> 2   6  7
#> 3   8 14

count(mtcars$cyl)
#> Error in UseMethod("count"): no applicable method for 'count' applied to an object of class "c('double', 'numeric')"

count(mtcars["cyl"], cyl) 
#>   cyl  n
#> 1   4 11
#> 2   6  7
#> 3   8 14

Created on 2023-05-30 with reprex v2.0.2

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.