I want to only display top 10 rows of individual_score on the below code. I am unable to achieve that. I tried top_n() after arrange but that is not working. I also tried to filter (individual_score == top_n()) but that did not work either.Can anyone help me how to achieve only 10 rows. With the code below it results 11,294 rows
There are a couple of things going on here. First, as @Yarnabrina mentioned, you need to provide top_n with the column to use for ranking. In your case, it would be (assuming you want the top 10 rows based on individual_score):
However, that will probably give you more than 10 rows, because your data are grouped by match after the summarize step. With grouped data, top_n will return the top 10 for each group. If you want the top 10 rows of the overall data frame then ungroup first:
@Yarnabrina's method of using head works as well. However, this might in general give unexpected results (within the tidyverse), because head doesn't respect grouping.
Thanks. Ungroup was missing on my code. slice and top_n both works after ungroup. Head works as well. Like @joels said head might give unexpected result i will use slice for my code