First generate some random data.
library(data.table)
library(epitools)
num <- sample(20:100, 100, replace = TRUE)
denom <- sample(100:500, 100, replace = TRUE)
id <- 1:100
thedata <- data.table(num, denom, id)
head(thedata, 20)## num denom id
## 1: 43 243 1
## 2: 100 201 2
## 3: 49 128 3
## 4: 98 226 4
## 5: 47 255 5
## 6: 24 228 6
## 7: 96 140 7
## 8: 24 214 8
## 9: 22 404 9
## 10: 45 241 10
## 11: 27 238 11
## 12: 28 292 12
## 13: 21 420 13
## 14: 67 152 14
## 15: 96 491 15
## 16: 73 302 16
## 17: 49 418 17
## 18: 39 378 18
## 19: 90 169 19
## 20: 71 480 20
Then add some columns.
thedata[, c('x', 'n', 'proportion', 'lower', 'upper',
'conf.level') := binom.wilson(num, denom)]
head(thedata, 20)## num denom id x n proportion lower upper conf.level
## 1: 43 243 1 43 243 0.17695473 0.13410918 0.22985504 0.95
## 2: 100 201 2 100 201 0.49751244 0.42908853 0.56602965 0.95
## 3: 49 128 3 49 128 0.38281250 0.30318626 0.46926772 0.95
## 4: 98 226 4 98 226 0.43362832 0.37065968 0.49881557 0.95
## 5: 47 255 5 47 255 0.18431373 0.14153121 0.23646643 0.95
## 6: 24 228 6 24 228 0.10526316 0.07176214 0.15184523 0.95
## 7: 96 140 7 96 140 0.68571429 0.60472787 0.75678125 0.95
## 8: 24 214 8 24 214 0.11214953 0.07653134 0.16144659 0.95
## 9: 22 404 9 22 404 0.05445545 0.03623337 0.08107069 0.95
## 10: 45 241 10 45 241 0.18672199 0.14257876 0.24069562 0.95
## 11: 27 238 11 27 238 0.11344538 0.07914710 0.16002388 0.95
## 12: 28 292 12 28 292 0.09589041 0.06717800 0.13509743 0.95
## 13: 21 420 13 21 420 0.05000000 0.03293268 0.07522441 0.95
## 14: 67 152 14 67 152 0.44078947 0.36428646 0.52021154 0.95
## 15: 96 491 15 96 491 0.19551935 0.16285958 0.23290649 0.95
## 16: 73 302 16 73 302 0.24172185 0.19687505 0.29305676 0.95
## 17: 49 418 17 49 418 0.11722488 0.08981544 0.15160573 0.95
## 18: 39 378 18 39 378 0.10317460 0.07639640 0.13793721 0.95
## 19: 90 169 19 90 169 0.53254438 0.45743480 0.60620733 0.95
## 20: 71 480 20 71 480 0.14791667 0.11895534 0.18246872 0.95