You could put the construction of your data.frame df
inside a function and then use replicate
:
my_fun <- function() {
ID <- sample(1:30, 100, rep=T)
Trait <- sample(0:1, 100, rep=T)
Year <- sample(1992:1999, 100, rep=T)
res <- tibble(Trait = Trait, Year = Year) %>%
group_by(Year) %>%
dplyr::summarise(
n_Trait = sum(Trait == 1),
n_total = length(Trait)) %>%
ungroup()
return(res)
}
bind_rows(replicate(10, my_fun(), simplify = FALSE))
This way you replicate the experiment ten times and can do further analysis afterwards.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…