Skip to content

Instantly share code, notes, and snippets.

@dceoy
dceoy / row_fisher_df.R
Last active June 6, 2021 02:05
[R] Fisher's Exact Test on each row of a data frame
#!/usr/bin/env Rscript
# fisher test on each row
row_fisher <- function(row, alt = 'two.sided', cnf = 0.95) {
f <- fisher.test(matrix(row, nrow = 2), alternative = alt, conf.level = cnf)
return(c(row,
p_val = f$p.value,
or = f$estimate[[1]],
or_ll = f$conf.int[1],
or_ul = f$conf.int[2]))