title: How to reshape a dataframe with "reoccurring" columns?
body: <p>I am new to data analysis with R. I recently got a pre-formatted environmental observation-model dataset, an example subset of which is shown below:</p>
  
  <pre><code>date                   site      obs    mod      site           obs    mod
  2000-09-01 00:00:00    campus    NA     61.63    city centre    66     56.69
  2000-09-01 01:00:00    campus    52     62.55    city centre    NA     54.75
  2000-09-01 02:00:00    campus    52     63.52    city centre    56     54.65
  </code></pre>
  
  <p>Basically, the data include the time series of hourly observed and modelled concentrations of a pollutant at various sites in "reoccurring columns", i.e., site - obs - mod (in the example I only showed 2 out of the total 75 sites). I read this "wide" dataset in as a data frame, and wanted to reshape it into the "narrower" format as:</p>
  
  <pre><code>date                   site           obs    mod
  2000-09-01 00:00:00    campus         NA     61.63
  2000-09-01 01:00:00    campus         52     62.55
  2000-09-01 02:00:00    campus         52     63.52
  2000-09-01 00:00:00    city centre    66     56.69
  2000-09-01 01:00:00    city centre    NA     54.75
  2000-09-01 02:00:00    city centre    56     54.65
  </code></pre>
  
  <p>I believed that I should use the package "reshape2" to do this.  Firstly I tried to melt and then dcast the dataset:</p>
  
  <pre><code>test.melt &lt;- melt(test.data, id.vars = "date", measure.vars = c("site", "obs", "mod"))
  </code></pre>
  
  <p>However, it only returned half of the data, i.e., records of the site(s) ("city centre") following the first one ("campus") were all cut off:</p>
  
  <pre><code>date                   variable    value
  2001-01-01 00:00:00    site        campus
  2001-01-01 01:00:00    site        campus
  2001-01-01 02:00:00    site        campus
  2001-01-01 00:00:00    obs         NA
  2001-01-01 01:00:00    obs         52
  2001-01-01 02:00:00    obs         52
  2001-01-01 00:00:00    mod         61.63
  2001-01-01 01:00:00    mod         62.55
  2001-01-01 02:00:00    mod         63.52
  </code></pre>
  
  <p>I then tried recast:</p>
  
  <pre><code>test.recast &lt;- recast(test.data, date ~ site + obs + mod)
  </code></pre>
  
  <p>However, it returned with error message:</p>
  
  <pre><code>Error in eval(expr, envir, enclos) : object 'site' not found
  </code></pre>
  
  <p>I have tried to search for previous questions but have not found similar scenarios (correct me if I am wrong).  Could someone please help me with this?</p>
  
  <p>Many thanks in advance!</p>