I am trying to run binom.test
on a data.table
with both the X and N values provided for each row. I saw this post, which uses a static N value and tried to modify, but if I try I get:
dt = data.table(X=rbinom(100, 625, 1/5), N=rbinom(100, 625, 4/5))
dt[, P := binom.test(x=X, n=N)$p.value ]
# Error in binom.test(x = X, n = N) : incorrect length of 'x'
The post also mentions aggregating by=X
, but even still I get:
dt[, P := binom.test(x=X, n=N)$p.value, by=X ]
# Error in binom.test(x = X, n = N) : 'n' must be a positive integer >= 'x'
Despite N always being a positive integer greater than X. My goal is not to group by values of X though, I want a binom.test p-value for every row.