title: Transpose dplyr::tbl object
body: <p>I am using src_postgres to connect and dplyr::tbl function to fetch data from redshift database. I have applied some filters and top function to it using the dplyr itself. Now my data looks as below:</p>
  
  <pre><code>   riid   day         hour 
     &lt;dbl&gt; &lt;chr&gt;       &lt;chr&gt;
   1 5542. "THURSDAY " 12   
   2 5862. "FRIDAY   " 15   
   3 5982. "TUESDAY  " 15   
   4 6022. WEDNESDAY   16 
  
  My final output should be as below:
  riid    MON   TUES  WED   THUR   FRI   SAT  SUN
  5542                       12
  5862                             15
  5988           15
  6022                 16
  </code></pre>
  
  <p>I have tried spread. It throws the below error because of the class type:</p>
  
  <blockquote>
    <p>Error in UseMethod("spread_") :    no applicable method for 'spread_'
    applied to an object of class "c('tbl_dbi', 'tbl_sql', 'tbl_lazy',
    'tbl')"</p>
  </blockquote>
  
  <p>Since this is a really big table, I do not want to use dataframe as it takes a longer time. 
  I was able to use as below:</p>
  
  <pre><code>df_mon &lt;- df2 %&gt;% filter(day == 'MONDAY') %&gt;% mutate(MONDAY = hour) %&gt;% select(riid,MONDAY)
  df_tue &lt;- df2 %&gt;% filter(day == 'TUESDAY') %&gt;% mutate(TUESDAY = hour) %&gt;% select(riid,TUESDAY)
  df_wed &lt;- df2 %&gt;% filter(day == 'WEDNESDAY') %&gt;% mutate(WEDNESDAY = hour) %&gt;% select(riid,WEDNESDAY)
  df_thu &lt;- df2 %&gt;% filter(day == 'THURSDAY') %&gt;% mutate(THURSDAY = hour) %&gt;% select(riid,THURSDAY)
  df_fri &lt;- df2 %&gt;% filter(day == 'FRIDAY') %&gt;% mutate(FRIDAY = hour) %&gt;% select(riid,FRIDAY)
  </code></pre>
  
  <p>Is it possible to write all above in one statement?</p>
  
  <p>Any help to transpose this in a faster manner is really appreciated.</p>
  
  <p><strong>EDIT</strong>
  Adding the dput of the tbl object:</p>
  
  <pre><code>structure(list(src = structure(list(con = &lt;S4 object of class structure("PostgreSQLConnection", package = "RPostgreSQL")&gt;, 
      disco = &lt;environment&gt;), .Names = c("con", "disco"), class = c("src_dbi", 
  "src_sql", "src")), ops = structure(list(name = "select", x = structure(list(
      name = "filter", x = structure(list(name = "filter", x = structure(list(
          name = "group_by", x = structure(list(x = structure("SELECT riid,day,hour,sum(weightage) AS score FROM\n  (SELECT riid,day,hour,\n  POWER(2,(cast(datediff (seconds,convert_timezone('UTC','PKT',SYSDATE),TO_DATE(TO_CHAR(event_captured_dt,'mm/dd/yyyy hh24:mi:ss'),'mm/dd/yyyy hh24:mi:ss')) as decimal) / cast(7862400 as decimal))) AS weightage\n  FROM (\n  SELECT riid,convert_timezone('GMT','PKT',event_captured_dt) AS EVENT_CAPTURED_DT,\n  TO_CHAR(convert_timezone('GMT','PKT',event_captured_dt),'DAY') AS day,\n  TO_CHAR(convert_timezone('GMT','PKT',event_captured_dt),'HH24') AS hour\n  FROM Zameen_STO_DATA WHERE EVENT_CAPTURED_DT &gt;= TO_DATE((sysdate -30),'yyyy-mm-dd') and LIST_ID = 4282\n  )) group by riid,day,hour", class = c("sql", 
          "character")), vars = c("riid", "day", "hour", "score"
          )), .Names = c("x", "vars"), class = c("op_base_remote", 
          "op_base", "op")), dots = structure(list(riid = riid, 
              day = day), .Names = c("riid", "day")), args = structure(list(
              add = FALSE), .Names = "add")), .Names = c("name", 
      "x", "dots", "args"), class = c("op_group_by", "op_single", 
      "op")), dots = structure(list(~min_rank(desc(~score)) &lt;= 
          1), .Names = ""), args = list()), .Names = c("name", 
      "x", "dots", "args"), class = c("op_filter", "op_single", 
      "op")), dots = structure(list(~row_number() == 1), .Names = ""), 
      args = list()), .Names = c("name", "x", "dots", "args"), class = c("op_filter", 
  "op_single", "op")), dots = structure(list(~riid, ~day, ~hour), class = "quosures", .Names = c("", 
  "", "")), args = list()), .Names = c("name", "x", "dots", "args"
  ), class = c("op_select", "op_single", "op"))), .Names = c("src", 
  "ops"), class = c("tbl_dbi", "tbl_sql", "tbl_lazy", "tbl"))
  </code></pre>