0

could not get top_n function to work on my data and the following does not seem to pull the top 5 rows as suggested in help

library(dplyr)
data("iris")

df <- iris %>%
  filter(Petal.Width>1) %>% 
  group_by(Petal.Width, Species)%>% 
  summarize(n = n()) %>% 
  arrange(n) %>% 
  top_n(5)
dim(df)
gregV
  • 987
  • 9
  • 28
  • 3
    You could use `ungroup()` after `arrange(n)`. [See this](https://stackoverflow.com/questions/27766054/getting-the-top-values-by-group) – GooJ Aug 30 '19 at 22:17
  • 2
    You are slicing the top 5 rows from each group. As @GooJ suggested, use `ungroup()` before `top_n(5)`. – r2evans Aug 30 '19 at 22:44

0 Answers0