I have a very long script of files that are read into R, and manipulated in many ways. I'm not too familiar with the language, but feel this can all be simplified.
For each file (or later, object it turns into) I have 6 versions, and the names always only differ in terms of these numbers (x1,x2,...,x6, or p1_yes,p2_yes,...,p6_yes)
I'm not sure how to apply loops over the various pieces of code to simplify it. Merging all those objects together 1-6 would not work due to some data manipulations I have to make that differ between them.
Just 3 examples:
agri1 <- raster("p1_agri.tif")
agri2 <- raster("p2_agri.tif")
agri3 <- raster("p3_agri.tif")
agri4 <- raster("p4_agri.tif")
agri5 <- raster("p5_agri.tif")
agri6 <- raster("p6_agri.tif")
pas1 <- as.data.frame(pas1)
pas2 <- as.data.frame(pas2)
pas3 <- as.data.frame(pas3)
pas4 <- as.data.frame(pas4)
pas5 <- as.data.frame(pas5)
pas6 <- as.data.frame(pas6)
apglm1 <- glm(test~agri+post,family="binomial",data=alldata1)
apglm2 <- glm(test~agri+post,family="binomial",data=alldata2)
apglm3 <- glm(test~agri+post,family="binomial",data=alldata3)
apglm4 <- glm(test~agri+post,family="binomial",data=alldata4)
apglm5 <- glm(test~agri+post,family="binomial",data=alldata5)
apglm6 <- glm(test~agri+post,family="binomial",data=alldata6)