title: How to set the row names of a data frame passed on with the pipe %>% operator?
body: <p>I have a data frame which I am <code>dcast</code>ing using the <code>reshape2</code> package, and I would like to remove the first column and have it become the row names of the data frame instead.</p>
  
  <p>Original dataframe, before <code>dcast</code>:</p>
  
  <pre><code>&gt; corner(df)
  
  ID_full      gene cpm
  1  S36-A1   DDX11L1   0
  2  S36-A1    WASH7P   0
  3  S36-A1 MIR1302-2   0
  4  S36-A1   FAM138A   0
  5  S36-A1     OR4F5   0
  </code></pre>
  
  <p><code>pivot</code> function to dcast the table:</p>
  
  <pre><code> library(reshape2)
  
   pivot &lt;- function(x){
               castTable &lt;- x %&gt;% dcast(ID_full ~ gene, value.var="cpm")
               }
  </code></pre>
  
  <p>After <code>dcast</code>, wrapped in my <code>pivot</code> function:</p>
  
  <pre><code>&gt; corner(df)
  
  ID_full 1060P11.3 A1BG A1BG-AS1 A1CF
  1  S36-A1         0    0        0    0
  2 S36-A10         0    0        0    0
  3 S36-A11         0    0        0    0
  4 S36-A12         0    0        0    0
  5  S36-A2         0    0        0    0
  </code></pre>
  
  <p>I'd like ID_full to become the rownames, and to cease existing as a column, piped after <code>dcasting</code>. I can do this in several lines, replacing the data frame each time, but I'd like to do it all using the <code>%&gt;%</code> operator.</p>
  
  <p>The best attempt I can think of would involve something like this, but obviously it doesn't work:</p>
  
  <pre><code>library(dplyr)
  
  df &lt;- df %&gt;% pivot(.) %&gt;% with(., row.names=df[,1])
  </code></pre>
  
  <p>I'd appreciate any suggestions... this nuisance is driving me crazy!</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Thanks for your answers:</p>
  
  <p>This expression works nicely:</p>
  
  <pre><code>df &lt;- df %&gt;% pivot(.) %&gt;% `rownames&lt;-`(.[,1]) %&gt;% select(-ID_full)
  
  &gt; corner(df)
  
          1060P11.3 A1BG A1BG-AS1 A1CF        A2M
  S36-A1          0    0        0    0    0.00000
  S36-A10         0    0        0    0    0.00000
  S36-A11         0    0        0    0    0.00000
  S36-A12         0    0        0    0    1.62189
  S36-A2          0    0        0    0 1170.95000
  </code></pre>