I have a huge dataframe with the following basic structure:
data <- data.frame(species = factor(c(rep("species1", 4), rep("species2", 4), rep("species3", 4))),
trap = c(rep(c("A","B","C","D"), 3)),
count=c(6,3,7,9,5,3,6,6,5,8,1,3))
data
I want simultaneously chi-square tests for the species counting data between the four traps for each individually species, but not between them. It could be solved with the following code for each individually species, but because of my huge original dataframe it is not a suitable solution for me.
chi_species1 <- xtabs(count~trap, data,
subset = species=="species1")
chi_species1
chisq.test(chi_species1)
Thanks for your help!!