Reputation: 21
I have the following code to apply in R:
qnorm(0.975)*sqrt(p*(1-p)/n)
Typically, I would enter the individual p and n values to get the output. However, I have a lot of data in Excel format, and to save time, I would like to apply the above code to an attached Excel file in R with data in following format. A sample from the excel file has data in following format:
Thank you very much!
Upvotes: 0
Views: 119
Reputation: 420
Yes, you need to import your excel file, for example, with the readxl
package. You can install it like this;
install.packages("readxl")
Upload the package and read your file:
library(readxl)
df <- read_excel("your file name here")
You can apply your formula in a dplyr pipe:
library(dplyr)
df <- df |>
mutate(result=qnorm(0.975)*sqrt(P*(1-P)/N))
Edit: you can save your dataframe to a CSV- or to an excel-file with writexl
or xlxs
package.
Upvotes: 0