What code could I use to make the x, n, and p, in the following code change with each row as it iterates through a dataframe?
prop.test(x=5328960, n=12810000, p=0.416, alternative="two.sided")
What code could I use to make the x, n, and p, in the following code change with each row as it iterates through a dataframe?
prop.test(x=5328960, n=12810000, p=0.416, alternative="two.sided")
 
    
     
    
    # create dataframe with values of x, n, p
df <- data.frame(x=c(1000, 200, 3000),
                 n=c(5000, 600, 8000),
                 p=c(0.1, 0.2, 0.3),
                 random_col=c(1, 2, 3))
# create function to calculate prop.test for each row
prop_test = function(row, output) {
  x = row[1]
  n = row[2]
  p = row[3]
  return(prop.test(x=x, n=n, p=p, alternative="two.sided"))
}
# calculate prop.test for each row
apply(df, 1, prop_test)
