How to split data frame into groups, combine rows I have a large data set with 405 columns, many rows, and data from 15 sites.  Each site has 27 columns, each one one quadrats data. Rows are species data.

I would like to split the data into the 15 sites and be able to use functions such as adding or averaging together all 27 columns to get an idea of the species presence at each site. I tried creating a vector of sites and using this to split the data.  

Example:

"n&lt;-rep(27,15)                    #repeats 27 15 times (15 sites, 27 quadrats per site in 2018)
names&lt;-c("BB", "BEP","BKP", "BP","BY",'DB','DP','H1P','LTP','NB','NP','NRP','OP','ZB','ZP')
sites18&lt;-as.factor(rep(names[rep(1:15, n)]) )     #site name replicated 27 times 


When I use the split function, it loses the species data and makes one long column for each site. 

split18&lt;-as.data.frame(split(t(p18),sites18))


I need another solution, perhaps something with an apply function, but I have been unable to find a good solution.
If I understood you correctly, you want to vertically split your data frame and horizontally union the resulting data frames. Here is an example for what I would do in this case:

#assuming exemplary dataset
dataset &lt;- data.frame(matrix(rnorm(n = 27 * 15 * 10), nrow = 10));
colnames(dataset) &lt;- paste(
  as.character(sites18)
  ,rep(1:27, length.out = 27 * 15)
  ,sep = "_");
str(dataset);

#create list of data frames using a vertical split
(list_df_by_group &lt;- lapply(
  names
  ,function(name) dataset[, paste(rep(name, 27), 1:27, sep = "_")]));
names(list_df_by_group) &lt;- names;
str(list_df_by_group);

#horizontally union data frames
final_dataset &lt;- data.frame(matrix(ncol = 28, nrow = 0));
colnames(final_dataset) &lt;- c("group", as.character(1:27));
for(name in names){
  colnames(list_df_by_group[[name]]) &lt;- as.character(1:27);
  final_dataset &lt;- rbind(
    final_dataset,
    cbind(
      data.frame(group = rep(name, nrow(list_df_by_group[[name]])))
      ,list_df_by_group[[name]]));
}
str(final_dataset);