0

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")
user438383
  • 5,716
  • 8
  • 28
  • 43
  • 1
    Welcome to stackoverflow: What have you tried? What are your coding problems? Could you provide an indication of your expected output? [Guidance for asking questions more likely to get help](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Peter Dec 04 '21 at 09:16
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Dec 08 '21 at 18:06

1 Answers1

0
# 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)