I am trying to aggregate data from per second to per minute (taking the average of all values over that minute). My data is timestamped of the form:

```
date time[h:m:s-03:00],X,value
2016-05-29 15:50:33-03:00,X,561
2016-05-29 15:50:34-03:00,X,565
....

```

I have hacked my way to an answer with the following code, but I would like to find a better, cleaner way to do this:

```
awk -F: 'BEGIN{
    foo_total=0;
    foo=0; }

    {
    split($4,ar,",");
    foo=ar[3];
    split($3,a,"-");
    if(a[1]~"00"){
            first_foo=ar[3]}
    if(a[1]!~"00"){
            foo_total+=ar[3]}

    foo_sum=(first_foo + foo_total);
    foo_final=foo_sum/60
    if(a[1]~"59") {printf $1":"$2","foo_final"\n"; foo_total=0; first_foo=0;} }' MyFile.csv

```

Your help is much appreciated!