I expect the code:
datab <- data.table(Events = c(79,68,54), Duration = c(61,44,72))
datab[, .(Poisson.High=poisson.test(Events, T = Duration)$conf.int[2])]
to produce:
nrow Poisson.High
1: 1 1.6140585
2: 2 1.9592319
3: 3 0.9785873
Instead it produces:
Error in poisson.test(Events, T = Duration) :
the case k > 2 is unimplemented
As I understand it, this is because poisson.test
's first argument can accept a vector as well as a scalar. In the vector case it must be two elements and no more. As there are 3 rows in the table the evaluation of the first row fails as it sees a vector with three elements as the first argument to poisson.test
.
How can I reference Events
in such a way that it provides only the scalar value associated with that row? (I've tried Events[1]
but that just uses the first row in datab
for obvious reasons.)