I would like to apply a function to all rows of a data frame where each application the columns as distinct inputs (not like mean
, rather as parameters).
I wonder what the tidy way is to do the following:
# Data
successes <- c(0,3,6,15,15,17,12,9,22,33)
trials <- c(50,1788,1876,3345,1223,856,342,214,265,257)
prognosis <- 0.01*c(0.05,0.10,0.25,0.5,0.75,1.3,2,3.4,6,10)
test_data = data.frame(successes = successes, trials = trials,
prognosis = prognosis, p_value1 = NA, p_value2 = NA)
for(i in 1: nrow(test_data)){
test_data$p_value1[i] = binom.test(test_data$successes[i], test_data$trials[i],
test_data$prognosis[i], "less")$p.value
test_data$p_value2[i] = binom.test(test_data$successes[i], test_data$trials[i],
test_data$prognosis[i], "greater")$p.value
}