title: reshape2 returning "Error in .fun(.value[0], ...) : 3 arguments passed to 'length' which requires 1"
body: <p>KEY aim: <em>To calculate the mean abundance of each species at each site, from three replicate samples per site</em>
  KEY variables: Site.Number, Replicate, species.</p>
  
  <p>I have replicate samples which need to be combined as a single sample unit for statistical analysis. The two microhabitats which were sampled have been divided into two separate frames, allowing for the data frames to be reduced to site number, habitat type, replicate number, and the 197 species:</p>
  
  <pre><code>sev.mci.bank &lt;- group_by(sev.mci.banklog[sev.mci.banklog$Habitat == "Bank Sweeps", ])
  sev.mci.log &lt;- group_by(sev.mci.banklog[sev.mci.banklog$Habitat == "Log Wash", ])
  </code></pre>
  
  <p>I am then trying to use reshape2 to average the replicate samples in order to reduce the number of samples of each species per site from three to one, by first rearranging the species data into single column form.</p>
  
  <pre><code>library(reshape2)
  as.data.frame(sev.mci.bank)
  
  column.bank &lt;- melt(sev.mci.bank, id=c('Site.Number', 'Habitat', 'Replicate'))
  </code></pre>
  
  <h1>This works fine, but then..</h1>
  
  <pre><code>mean.bank &lt;- acast(column.bank, Site.Number + Habitat ~ variable, value='value', FUN=mean)
  </code></pre>
  
  <h1>running this code returns</h1>
  
  <pre><code>"Error in .fun(.value[0], ...) : 3 arguments passed to 'length' which requires 1""
  </code></pre>
  
  <p>Please help! I can't figure out where to go from here. I initially tried to use tidyverse to do this, any recommendations are welcome.
  The code for this was found at <a href="https://www.r-bloggers.com/r-for-ecologists-creating-a-site-x-species-matrix/" rel="nofollow noreferrer">rbloggers.com</a></p>
  
  <p>My code in full:</p>
  
  <pre><code>sev.mci.banklog &lt;- read.csv ("/Users/Chloe/Desktop/Environmental Data Analysis/EDA.working.directory/SEVMCI_data_bank_log.csv")
  
  sev.mci.bank &lt;- group_by(sev.mci.banklog[sev.mci.banklog$Habitat == "Bank Sweeps", ])
  sev.mci.log &lt;- group_by(sev.mci.banklog[sev.mci.banklog$Habitat == "Log Wash", ])
  
  library(reshape2)
  as.data.frame(sev.mci.bank)
  head(sev.mci.bank)
  
  column.bank &lt;- melt(sev.mci.bank, id=c('Site.Number', 'Habitat', 'Replicate'))
  mean.bank &lt;- dcast(column.bank, Site.Number + Habitat ~ variable, value='value', FUN=mean)
  </code></pre>
  
  <p>My data:
  <a href="https://1drv.ms/u/s!AmagKxVfx5LXnwlDQTuNVm-luWqM" rel="nofollow noreferrer">link to .csv</a></p>
  
  <p>Thank you!</p>