Hi guys, I really need your help. Suppose that I have this data and computation, how do I calculate ANOVA for data in balance column for all i altogether?
fund <- data.frame(creditor = rep (LETTERS[1:26], 1), saving = sample(500:1000, 26))
for(i in 1:4) {
cash <- fund %>% mutate(interest= i* 0.01* saving,
balance= saving + interest)
print(cash)
}
I interpret this as a request to understand effective ways to loop over table manips and stitch the results together to a single table.
The idea I will show you is using one of the map* familiy of functions from the purrr package, which is part of the tidyverse suite of packages (as you already use dplyr::mutate
library(tidyverse)
fund <- data.frame(creditor = rep (LETTERS[1:26], 1), saving = sample(500:1000, 26))
cash_all_i <- map_dfr(1:4, \(i){
fund |> mutate(
interest = i * 0.01 * saving,
balance = saving + interest,
i = i
)
})
cash_all_i