Hello,
I have a large tabel with columns; "date" "location" "value" "file"
I would like to aggregate all the values within the same file on the same date but with different locations.
The table looks like below
datetime location value fn
<dttm> <chr> <dbl> <chr>
1 1996-01-01 00:00:00 inl_1 4200 2010-GF
2 1996-01-02 00:00:00 inl_1 4400 2010-GF
3 1996-01-03 00:00:00 inl_1 4350 2010-GF
4 1996-01-04 00:00:00 inl_1 4000 2010-GF
5 1996-01-01 00:00:00 inl_2 3510 2010-GF
6 1996-01-02 00:00:00 inl_2 3560 2010-GF
7 1996-01-03 00:00:00 inl_2 3500 2010-GF
8 1996-01-04 00:00:00 inl_1 4000 2013-GF
What I would like to get is something like:
datetime location value fn
<dttm> <chr> <dbl> <chr>
1 1996-01-01 00:00:00 inl_1 7710 2010-GF
2 1996-01-02 00:00:00 inl_1 7960 2010-GF
3 1996-01-03 00:00:00 inl_1 7850 2010-GF
4 1996-01-04 00:00:00 inl_1 4000 2010-GF
8 1996-01-04 00:00:00 inl_1 4000 2013-GF
I have tried this but it doesnt work:
result <- aggregate(. ~datetime+fn, data = df, sum, na.rm=TRUE)
The error I get is:
Error in Summary.factor(2:1, na.rm = TRUE) :
‘sum’ not meaningful for factors
Does anyone know?