I think the issue is because you named the vector of Bacteria names as Bacteria (same name as the column). This causes a problem in the for-loop at this part subset = (Bacteria == Bacteria[i]))
I stored the bacteria names in a differently named vector called bacteria_names and edited the other occurrences accordingly, and it works fine:
names(all_csv)[1] <- "Bacteria"
bacteria_names <- unique(all_csv$Bacteria)
df <- data.frame(matrix(NA, ncol = 7, nrow = length(bacteria_names)))
df[, 1] <- bacteria_names
names(df) <- c("Bacteria", "estimate", "se", "zval", "pval", "ci.lb", "ci.ub")
df
for(i in 1:length(bacteria_names)){
ma_model <- rma.mv(yi, vi, data = all_csv, subset = (Bacteria == bacteria_names[i]))
re_table <- coef(summary(ma_model))
df[i, -1] <- re_table
}
df
Bacteria estimate se zval pval ci.lb ci.ub
1 Caraquez -1.38323940 0.3817494 -3.62342295 2.907298e-04 -2.1314544 -0.6350244
2 Franzen -1.96817463 0.1450495 -13.56898662 6.116178e-42 -2.2524664 -1.6838828
3 Lieu -0.67038982 0.0914624 -7.32967639 2.307091e-13 -0.8496528 -0.4911268
4 McMullin -0.03752519 0.4471840 -0.08391443 9.331245e-01 -0.9139897 0.8389393
5 Meyer -1.00999884 0.1206731 -8.36971327 5.775860e-17 -1.2465137 -0.7734840
Edit:
While my above discussion still stands (if you named both column and vector Bacteria you will get repeated results), I just noticed your quoted error was with the earlier naming of study and study_types. It seems the Processing terminated since k <= 1. error comes from the metafor package itself rather than an issue with the loop. I suppose the rma.mv function terminates when there is k <= 1 studies left?