I'm running a number of power analyses, testing different observation sizes keeping all else equal, and would like to save the results as rows in a dataframe so that I can visualise them later in ggplot.
results_df <- data.frame()
# create function leaving user to control n= as an input parameter
run_power_analysis <- function(n){
power_analysis <- pwr.t.test(n=n,
sig.level=0.05,
power=NULL,
d=0.2,
type="one.sample",
alternative = "two.sided")
# save $n and $power as a row in df
results_df <- rbind(results_df, power_analysis[c(1,4)])
return(results_df)
}
But this doesn't seem to update results_df
. R returns only 1 row, why is this? And how can I get the whole df?