How to order by max count of repeated rows and organize them by another row

Hi, im trying to get the top 3 variables in a cyclist store, im having problems to get the top 3 most used start_stations and separate them by users

now i have this code but i dont what to do from now on

Cyclist_df %>%
group_by(Cyclist_df$station_start) %>%
count(Cyclist_df$station_star)

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

  1. This exercise appears to be about a bike-share system, not a cyclist (bicycle?) store. The dataset probably has a station_start and station_end for each ride. A reprex with a minimal dataset will clear this up.
  2. What do you mean by the top three variables? My guess is that you want the top three stations based on the number of rides that start there. A station is not a variable.
  3. The count() function will report just one value for each group. I think you want to create a new column in your data set instead. Look at the following reprex using the mtcars data set and compare the code and the three outputs. Also note the proper use of the pipe operator.
library(tidyverse)

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

mtcars %>%
  group_by(cyl) %>%
  summarise(n = n())
#> # A tibble: 3 × 2
#>     cyl     n
#>   <dbl> <int>
#> 1     4    11
#> 2     6     7
#> 3     8    14

# look for the new column named n:
mtcars %>%
  group_by(cyl) %>%
  mutate(n = n())
#> # A tibble: 32 × 12
#> # Groups:   cyl [3]
#>      mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb     n
#>    <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int>
#>  1  21       6  160    110  3.9   2.62  16.5     0     1     4     4     7
#>  2  21       6  160    110  3.9   2.88  17.0     0     1     4     4     7
#>  3  22.8     4  108     93  3.85  2.32  18.6     1     1     4     1    11
#>  4  21.4     6  258    110  3.08  3.22  19.4     1     0     3     1     7
#>  5  18.7     8  360    175  3.15  3.44  17.0     0     0     3     2    14
#>  6  18.1     6  225    105  2.76  3.46  20.2     1     0     3     1     7
#>  7  14.3     8  360    245  3.21  3.57  15.8     0     0     3     4    14
#>  8  24.4     4  147.    62  3.69  3.19  20       1     0     4     2    11
#>  9  22.8     4  141.    95  3.92  3.15  22.9     1     0     4     2    11
#> 10  19.2     6  168.   123  3.92  3.44  18.3     1     0     4     4     7
#> # … with 22 more rows

Created on 2022-01-14 by the reprex package (v2.0.1)

This topic was automatically closed 21 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.