[Solved] Selecting column sequences and creating variables

We could split the dataset (‘df’) with ‘1416’ columns to equal size ‘118’ columns by creating a grouping index with gl lst <- setNames(lapply(split(1:ncol(df), as.numeric(gl(ncol(df), 118, ncol(df)))), function(i) df[,i]), paste0(‘site’, 1:12)) Or you can create the ‘lst’ without using the split lst <- setNames(lapply(seq(1, ncol(df), by = 118), function(i) df[i:(i+117)]), paste0(‘site’, 1:12)) If we need … Read more