title: Using reshape function in R, with constant variables varying
body: <p>I want to use the reshape function in R with wide format to analyze weather data noted from stations over three years: 1996, 2006, and 2016.</p>
  <p>I have combined the three data sets in long format manually, but some variables such as longitude and latitude are not supposed to vary from one year to another. However some are different.</p>
  <p>I get the warning : some constant variables (Nom,Lat,Long) are really varying, when I apply reshape, which is expected.</p>
  <p>In this case, the aim is to have these variables, in the resulting wide format, containing the values observed in the year 2016.</p>
  <p>Note: the weather stations are not all present in all the three years.</p>
  <p>Here is an example:</p>
  <pre class="lang-r prettyprint-override"><code>a &lt;- c(rep(2, 4), rep(4, 3))
  b &lt;- c(rep(2, 3), 5, rep(4, 3), 4, 5, 3)
  c &lt;- c(1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
  name &lt;- c('a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 
            'c', 'd', 'r', 't', 'y', 'u', 'q', 'z')
  year &lt;- c(rep(2002, 7),rep(2005, 10))
  df &lt;- cbind(id = c, pos = c(a,b), year, name)
  df &lt;- as.data.frame(df)
  </code></pre>
  <p>df would be as follows:</p>
  <pre><code>&gt; df
     id pos year name
  1   1   2 2002    a
  2   2   2 2002    b
  3   3   2 2002    c
  4   4   2 2002    d
  5   5   4 2002    e
  6   6   4 2002    f
  7   7   4 2002    g
  8   1   2 2005    a
  9   2   2 2005    b
  10  3   2 2005    c
  11  4   5 2005    d
  12  5   4 2005    r
  13  6   4 2005    t
  14  7   4 2005    y
  15  8   4 2005    u
  16  9   5 2005    q
  17 10   3 2005    z
  </code></pre>
  <p>now to go to wide format using reshape:</p>
  <pre class="lang-r prettyprint-override"><code>dfw &lt;- reshape(df, direction = &quot;wide&quot;, timevar = &quot;year&quot;, 
                 idvar = &quot;id&quot;, v.names = &quot;pos&quot;)
  </code></pre>
  <blockquote>
  <p>Warning message:
  In reshapeWide(data, idvar = idvar, timevar = timevar, varying = varying, :
  some constant variables (name) are really varying</p>
  </blockquote>
  <pre><code>&gt; dfw
     id name pos.2002 pos.2005
  1   1    a        2        2
  2   2    b        2        2
  3   3    c        2        2
  4   4    d        2        5
  5   5    e        4        4
  6   6    f        4        4
  7   7    g        4        4
  15  8    u     &lt;NA&gt;        4
  16  9    q     &lt;NA&gt;        5
  17 10    z     &lt;NA&gt;        3
  </code></pre>
  <p>I got what I need: pos varying over time.</p>
  <p>My problem is: in the year 2002, observations with id 5, 6, and 7 had the respective names e, f, and g. However in 2005, they had the respective names r, t, and y. the wide format table dfw shows the names given in 2002</p>
  <p>I want the result in the reshape function to present the names defined in 2005 for this type of observations.</p>
  <p>Is there something to be modified in the reshape function? maybe in another package?</p>
  <p>Note that these are two separate tables initially one for each year, and the were manually combined, so perhaps a modification can be made before combining?</p>