The dataset is as follows:
DATE | ID | Value | Temp |
---|---|---|---|
01-01-2000 | 1 | 1 | 21 |
01-01-2000 | 1 | 4 | 21 |
02-01-2000 | 2 | 9 | 34 |
02-01-2000 | 3 | 5 | 37 |
02-01-2000 | 3 | 4 | 37 |
I expect this outcome:
DATE | ID | Value | Temp |
---|---|---|---|
01-01-2000 | 1 | 5 | 21 |
02-01-2000 | 2 | 9 | 34 |
02-01-2000 | 3 | 9 | 37 |
I try to use aggregate but it cannot keep the variable - Temp
Please give me some suggestions, thank you
aggregate(data$Value, by=list(Date=data$ID), FUN=sum)
The above code only returned:
DATE | Value |
---|---|
01-01-2000 | 5 |
02-01-2000 | 9 |
02-01-2000 | 9 |