title: An easier way to manipulate my data?
body: <p>I have a species x site matrix with treatment types and months attached to each site sampled. I've managed to restructure my data in the way I want using a bunch of loops and extra lines of code but I'm curious to how I can code this in a more efficient manner that works as new data comes in.</p>
  
  <p>Data:</p>
  
  <pre><code>time&lt;-structure(list(Month = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
  2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
  2L), .Label = c("February", "March"), class = "factor"), Treatment = structure(c(2L, 
  2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 
  2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 
  1L, 1L, 2L, 1L, 2L, 1L, 1L), .Label = c("C", "T"), class = "factor"), 
      Site = structure(c(13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 
      1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
      15L, 16L, 17L, 18L, 19L, 20L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 
      8L, 9L, 10L, 11L, 12L), .Label = c("SHA10RA", "SHA10RB", 
      "SHA10RC", "SHA10RD", "SHA10RE", "SHA10RF", "SHA11RA", "SHA11RB", 
      "SHA11RC", "SHA11RD", "SHA11RE", "SHA11RF", "SHA1RA", "SHA1RB", 
      "SHA1RC", "SHA4RA", "SHA5RA", "SHA5RB", "SHA5RC", "SHA5RD"
      ), class = "factor"), Pheidole.adrianoi = c(0L, 5L, 0L, 1L, 
      0L, 0L, 0L, 0L, 3L, 4L, 1L, 4L, 3L, 2L, 0L, 0L, 0L, 1L, 0L, 
      0L, 1L, 5L, 1L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 
      0L, 0L, 0L, 4L, 0L, 0L), Pheidole.floridana = c(1L, 1L, 6L, 
      1L, 7L, 6L, 0L, 0L, 0L, 0L, 1L, 0L, 3L, 1L, 4L, 3L, 3L, 5L, 
      5L, 0L, 0L, 0L, 2L, 1L, 6L, 5L, 1L, 3L, 0L, 0L, 3L, 0L, 2L, 
      1L, 4L, 5L, 5L, 0L, 7L, 0L), Pheidole.metallescens = c(5L, 
      0L, 4L, 2L, 0L, 0L, 0L, 0L, 2L, 2L, 2L, 1L, 0L, 4L, 0L, 0L, 
      0L, 1L, 0L, 0L, 3L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 2L, 1L, 
      0L, 2L, 3L, 0L, 0L, 0L, 0L, 0L, 0L), Solenopsis.carolinensis = c(0L, 
      6L, 2L, 3L, 5L, 2L, 0L, 5L, 2L, 5L, 5L, 7L, 5L, 4L, 8L, 4L, 
      4L, 6L, 4L, 7L, 2L, 0L, 0L, 2L, 2L, 3L, 0L, 4L, 0L, 3L, 4L, 
      0L, 2L, 2L, 4L, 0L, 1L, 5L, 1L, 7L), Solenopsis.invicta = c(0L, 
      0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
      0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 
      0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Solenopsis.nickersoni = c(0L, 
      0L, 0L, 0L, 0L, 4L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
      0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 
      0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Solenopsis.pergandei = c(2L, 
      2L, 1L, 1L, 0L, 1L, 4L, 3L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 
      1L, 0L, 0L, 3L, 0L, 0L, 3L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
      0L, 0L, 1L, 4L, 3L, 0L, 0L, 1L, 3L), Solenopsis.tennesseensis = c(0L, 
      0L, 0L, 2L, 1L, 1L, 1L, 2L, 0L, 2L, 1L, 1L, 1L, 4L, 3L, 2L, 
      3L, 1L, 2L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 
      0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L), Solenopsis.tonsa = c(0L, 
      0L, 1L, 0L, 1L, 0L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
      0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
      0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("Month", 
  "Treatment", "Site", "Pheidole.adrianoi", "Pheidole.floridana", 
  "Pheidole.metallescens", "Solenopsis.carolinensis", "Solenopsis.invicta", 
  "Solenopsis.nickersoni", "Solenopsis.pergandei", "Solenopsis.tennesseensis", 
  "Solenopsis.tonsa"), class = "data.frame", row.names = c(NA, 
  -40L))
  </code></pre>
  
  <p>code:</p>
  
  <pre><code>Species&lt;-colnames(time)[4:12]
  Sites&lt;-time$Site
  Treatment&lt;-time$Treatment
  Treatment&lt;-as.character(Treatment)
  Month&lt;-time$Month
  Month&lt;-as.character(Month)
  Species&lt;-rep(Species,40)
  Sites&lt;-as.character(Sites)
  
  Site&lt;-NULL
  for (i in 1:length(Sites)) {
    Site1&lt;-rep(Sites[i],9)
    Site&lt;-append(Site,Site1)
  }
  Site
  as.vector(Site)
  length(Species)
  length(Site)
  
  Period&lt;-NULL
  for (i in 1:length(Month)) {
    Month1&lt;-rep(Month[i],9)
    Period&lt;-append(Period,Month1)
  }
  Period
  Type&lt;-NULL
  for (i in 1:length(Treatment)) {
    Treat1&lt;-rep(Treatment[i],9)
    Type&lt;-append(Type,Treat1)
  }
  Type
  
  Abundance&lt;-NULL
  for (i in 1:40) {
    Occurence&lt;-t(time[i,4:12])
    Abundance&lt;-append(Abundance,Occurence)
  }
  Abundance
  length(Abundance)
  class(Abundance)
  
  df1&lt;-data.frame(Period,Type,Site, Species, Abundance)
  df1
  </code></pre>
  
  <p>I know the package reshape2 could probably help me but I am having trouble understanding exactly how I can optimize it for my use. Any help would be great!</p>