I wish to create a data frame from another data frame by selecting the max of subsets from the 1st data frame. Say I have the 1st data frame
df:
name date weekday util
---- ---- ------- ----
alpha 201801 1 10.1
alpha 201801 2 7.1
alpha 201801 3 1.1
alpha 201801 4 4.1
bravo 201801 1 9.9
bravo 201801 2 8.9
bravo 201801 3 1.9
bravo 201801 4 11.9
charlie 201801 1 0.1
charlie 201801 2 2.0
charlie 201801 3 7.3
charlie 201801 4 5.0
I wish to create another data frame using the max util for every unique date, name tuple
df_unique:
name date util
----- ---- ----
alpha 201801 10.1
bravo 201801 11.9
charlie 201801 7.3
I know we can choose a max by using
>max(df[df$name == 'alpha' && df$date == 201801, df$util])
10.1
However how would we do this for every unique name, date tuple. Is this even possible or do I need to create a function to do this?