So I have cattle, and a lot of them. I'm trying to add a column to my dataframe that is the total number of cattle per day, based on several counts summed over the course of a single day. I have this dataframe:
Guirvidig
# A tibble: 494 × 8
# Year Week Date Location Animals From To Notes
# <int> <int> <date> <chr> <int> <chr> <chr> <chr>
# 2010 31 2010-08-01 GUIRVIDIG 580 Bongor – Tchad BANKI NIGERIA RAS
And what I'm getting is:
Guirvidig$TotalAnimals <- aggregate(Animals~Date,Guirvidig,sum)
Error in
$<-.data.frame
(*tmp*
, TotalAnimals, value = list(Date = c(14822, : replacement has 136 rows, data has 494`
Of course the data has more rows, as the replacement is the sum of the rows from the original. How can I have the replacement row be the same for every single row of the same day or just show the sum for the day at the first row for that day? Any help will be appreciated.