dataframe - Two equal max values in R -


i have dataframe numbers(score) , repeating id. want maximum value each of id. used function

top = aggregate(df$score, list(df$id),max) 

this returned me top dataframe maximum values corresponding each id.

but happens 1 of id, have 2 equal max value. function ignoring second value.

is there way retain both max values.?

for example:

df

id   score 1    12 1    15 1    1 1    15 2    23 2    12 2    13 

the above function gives me this: top

id    score 1     15 2     23 

i need this: top

id   score 1    15 1    15 2    23 

i recommend data.table chris mentioned (good speed, steeper learning curve). or if don't want data.table use plyr:

library(plyr) ddply(df, .(id), subset, score==max(score)) # same ddply(df, .(id), function (x) subset(x, score==max(score))) 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -

Why does a .NET 4.0 program produce a system.unauthorizedAccess error on a Windows Server 2012 machine with .NET 4.5 installed? -