I am hoping someone may be able to help me to calculate the age (in days) of each animal in my data set?
My data look like the below and describe individual animals captured and measured through time. example$frab.num is a factor variable that provides a unique animal identifier, example$date is a date variable (class "Date") that describes the date that the animal was captured and example$wt is the weight of the animal at capture in grams.
In total my data frame includes >3800 individual animals that have been captured between 1996 and 2020. Some animals are caught up to 30 times during their life, but on average animals only live for 1-3 years and may be captured only 3 or 4 times during their life.
> example
   frab.num       date   wt
1       001 1996-10-22 1600
2       002 1996-10-22 1450
3       003 1996-10-22 1800
4       004 1996-10-22 1450
5       005 1996-10-22 1700
6       006 1996-10-22 1750
7       007 1996-10-22 1800
8       008 1996-10-22 1350
9       009 1996-10-22 1750
10      010 1996-10-22 1100
11      011 1996-10-22 1000
12      012 1996-10-22 1400
13      013 1996-10-22 1750
14      014 1996-10-22 1400
15      015 1996-10-22 1200
16      016 1996-10-22  700
17      017 1996-10-22 1000
18      018 1996-10-22  450
19      019 1996-10-22  300
20      020 1996-10-22 1100
If an animal is first caught before 1500 grams weight then we can calculate their age in days because we know that they grow approximately 10 grams per day on average. This will obtain an age at first capture for each individual animal. We can then calculate the age of each animal at subsequent capture dates by adding age at first capture date and the time difference in days between the first and subsequent capture dates. We cannot calculate the age of animals that are >1500 grams when first captured.
EDIT: a large example dataset can be accessed here
EDIT 2: an example of what the output would look like is below. Note that this is only a small example so no re-captures are included. NA values in age represent instances where the animal was greater than 1500 grams when first captured and hence age could not be calculated.
> example
   frab.num       date   wt age
1       001 1996-10-22 1600 NA
2       002 1996-10-22 1450 145
3       003 1996-10-22 1800 NA
4       004 1996-10-22 1450 145
5       005 1996-10-22 1700 NA
6       006 1996-10-22 1750 NA
7       007 1996-10-22 1800 NA
8       008 1996-10-22 1350 135
9       009 1996-10-22 1750 NA
10      010 1996-10-22 1100 110
11      011 1996-10-22 1000 100
12      012 1996-10-22 1400 140
13      013 1996-10-22 1750 NA
14      014 1996-10-22 1400 140
15      015 1996-10-22 1200 120
16      016 1996-10-22  700  70
17      017 1996-10-22 1000 100
18      018 1996-10-22  450  45
19      019 1996-10-22  300  30
20      020 1996-10-22 1100 110
Thank you in advance