Imagine I have this dataset:

```
id data_level var1    var2
aa   h         1       4
bb   l         2       5
cc   l         1.4     4.2
dd   h         1.3     3.8

```

I would like to add new rows to get this:

```
id data_level var1    var2
aa   h         1       4
bb   l         2       5
cc   l         1.4     4.2
dd   h         1.3     3.8
h    h         2.3     3.9
l    l         3.4     4.6
All  All       5.7     4.25

```

Where the new row are respectively:

In var 1 the sum for all values with data\_level = h, sum for all values with data\_level = l, sum for all values

In var 2 the average for all values with data\_level = h, average for all values with data\_level = l, average for all values.

It's basically an aggregation of data conditional on data level. Is there a fancy way to do it?