'How to do a t test for two groups for multiple variables on R?

I have 8 different groups and 60 variables. I would like to do a t test on group 1&2 for each metabolite and group 2&3, 2&4, 2&5, 2&6, 2&7, 2&8 for each metabolite. How do I do this? I have already made a loop for generating boxplots of my data that looks like this:

for(i in 2:ncol(data)){
  print (ggboxplot(data, x="Group",y= colname[i], ylab="") + geom_point()+ ggtitle(colname[i]))   
  ggsave(path = "boxplot", filename = paste("boxplot_", colname[i], ".png"))
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source