Select rows in the top n groups according to some summarization operation

top_n_groups(df, group_var, val_var, val_fun = sum)

Arguments

df

data frame

group_var

grouping variable

val_var

value assessment variable to be summarized by group

val_fun

value assessment function to apply to val_var by group

Value

data frame only with observations from top groups