Allocate `total`

to `countByYear`

for a constant count per day between `start`

and `end`

.

1 | ```
countByYear(start, end, total=1)
``` |

`start, end` |
objects of class "Date" specifying the start, end, respectively, of the event |

`total` |
A number to be allocated by year in proportion to the number of days in the event each year. |

a numeric vector whose `sum`

is
`total`

with names for all the years between
`start`

and `end`

Spencer Graves

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | ```
##
## 1. All in one year
##
start73 <- as.Date('1973-01-22')
tst1 <- countByYear(start73, start73+99, 123)
# check
tst1. <- 123
names(tst1.) <- 1973
all.equal(tst1, tst1.)
##
## 2. Two years
##
tst2 <- countByYear(start73, start73+365, 123)
# check
dur <- 366
days1 <- (365-21)
days2 <- 22
tst2. <- 123 * c(days1, days2)/dur
names(tst2.) <- 1973:1974
all.equal(tst2, tst2.)
##
## 3. Ten years
##
tst10 <- countByYear(start73, start73+10*365.2, 123)
# check
days <- (c(rep(c(rep(365, 3), 366), length=10), 0)
+ c(-21, rep(0, 9), 22) )
tst10. <- 123 * days/(10*365.2+1)
names(tst10.) <- 1973:1983
all.equal(tst10, tst10.)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

All documentation is copyright its authors; we didn't write any of that.