subset dataframe with topmost values based on a category in r -


this question has answer here:

i have data frame this

type    value cella   2.02 cella   2.56 cellb   1.24 cellb   2.34 cellb   4.56 cellc   3.55 cellc   2.36 cellc   6.78 cellc   3.56 

and want subset based on topmost value each type,,, output be

type    value cella   2.56 cellb   4.56 cellc   6.78 

how can achieve in r - unique command can of - bit struck::: suggestions

m

using dplyr can done top_n

library(dplyr) # assume data in data frame df2 df2 %>% group_by(type) %>% top_n(1) 

you get

selecting value source: local data frame [3 x 2] groups: type     type value 1 cella  2.56 2 cellb  4.56 3 cellc  6.78 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -