title: Reshaping data frame 8 rows to 2 rows
body: <pre><code>df&lt;-structure(list(AC_NAME = c(&quot;Behat&quot;, &quot;Behat&quot;, &quot;Behat&quot;, &quot;Behat&quot;, 
  &quot;Nakur&quot;, &quot;Nakur&quot;, &quot;Nakur&quot;, &quot;Nakur&quot;), CAND_NAME = c(&quot;MAHAVEER SINGH RANA&quot;, 
  &quot;NARESH&quot;, &quot;UMAR ALI KHAN&quot;, &quot;AJAY CHAUHAN&quot;, &quot;DR. DHARAM SINGH SAINI&quot;, 
  &quot;IMRAN MASOOD&quot;, &quot;FIROZ AFTAB&quot;, &quot;GOVIND CHOUDHARY&quot;), PARTYABBRE = c(&quot;BSP&quot;, 
  &quot;INC&quot;, &quot;SP&quot;, &quot;BJP&quot;, &quot;BSP&quot;, &quot;INC&quot;, &quot;SP&quot;, &quot;IND&quot;), TOTVOTPOLL = c(70274, 
  69760, 47366, 23623, 89187, 84623, 29503, 14226), POSITION = c(1, 
  2, 3, 4, 1, 2, 3, 4)), row.names = c(NA, 8L), class = &quot;data.frame&quot;)
  
  &gt;df 
    AC_NAME              CAND_NAME PARTYABBRE TOTVOTPOLL POSITION
  1   Behat    MAHAVEER SINGH RANA        BSP      70274        1
  2   Behat                 NARESH        INC      69760        2
  3   Behat          UMAR ALI KHAN         SP      47366        3
  4   Behat           AJAY CHAUHAN        BJP      23623        4
  5   Nakur DR. DHARAM SINGH SAINI        BSP      89187        1
  6   Nakur           IMRAN MASOOD        INC      84623        2
  7   Nakur            FIROZ AFTAB         SP      29503        3
  8   Nakur       GOVIND CHOUDHARY        IND      14226        4
  </code></pre>
  <p>I want this to reshape like this.</p>
  <pre><code>data
    AC_NAME        Candidate_Rank1 Candidate_Rank2 Candidate_Rank3  Candidate_Rank4 Party_Rank1 Party_Rank2 Party_Rank3 Party_Rank4 Votes_Rank1 Votes_Rank2 Votes_Rank3
  1   Behat    MAHAVEER SINGH RANA          NARESH   UMAR ALI KHAN     AJAY CHAUHAN         BSP         INC          SP         BJP       70274       69760       47366
  2   Nakur DR. DHARAM SINGH SAINI    IMRAN MASOOD     FIROZ AFTAB GOVIND CHOUDHARY         BSP         INC          SP         IND       89187       84623       29503
    Votes_Rank4 Poistion1 Poistion2 Poistion3 Poistion4
  1       23623         1         2         3         4
  2       14226         1         2         3         4
  </code></pre>
  <p>I have tried <code>dcast</code>. Using it I am having more than desired columns.  I think it won't work here I am not sure. Someone guide me.I dont mind that column names be the same as mine they can be changed later.</p>
  <pre><code>dd &lt;- dcast(data, AC_NAME+CAND_NAME ~POSITION ,value.var = &quot;POSITION&quot;)             
  
  </code></pre>