extract top 5 value per group data.table r code example Example: r extract top values from data frame top_myvar <- head(arrange(df, desc(myvar)), n = 10)