I have a dataframe which looks like the following:
ID month country count style
1 2012-02 UK 3 high
1 2012-02 US 10 high
1 2012-02 FR 5 high
etc
Now, I want to aggregate the values over the ID
and country
variable and, therefore, I use:
aggregated_data = setDT(subset)[, .(Country = list(Country), ID = min(ID),
count = sum(count), by = list(Model, Month)][]
To get
ID month country count
1 2012-02 UK, US, FR 18
etc
However, since my style
variable is a factor I do not know how I can incorporate this in the aggregated table. The values of the factor variable is always the same for one ID
, so I only need to print the first value of the style
variable for the style
variable in the aggregated table. Does anyone know how to do this?