title: Error in order(x, ..., na.last = na.last, decreasing = decreasing) :argument 1 is not a vector?
body: <p>I have huge <code>data.frame</code>, a sample of which looks as shown below:</p>
  
  <pre><code>df &lt;- read.table(header=TRUE, text="
  id    BSheetyearlag  sd
  1001  Mar-1997       0.50
  1001  Mar-1997       0.40
  1001  Mar-1997       0.30
  1001  Mar-1997       0.20
  1001  Mar-1997       0.10
  1001  Mar-1998       0.20
  1001  Mar-1998       0.30", stringsAsFactors=FALSE)
  </code></pre>
  
  <p>I want to lag the column <code>sd</code> by 4 days and I run the following codes:</p>
  
  <pre><code>df &lt;- as.data.table(df)
  df[, lag_sd := lag(as.zoo(sd), k=4, na.pad=T), by=c("id", "BSheetyearlag")]
  </code></pre>
  
  <p>It runs well. However, when I want to proceed or to see how my <code>data.frame</code> looks like (using for instance <code>head</code> function):</p>
  
  <pre><code>df &lt;- as.data.frame(df)
  head(df)
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>Error in <code>order(x, ..., na.last = na.last, decreasing = decreasing)</code> : 
      argument 1 is not a vector </p>
  </blockquote>
  
  <p>Does anyone know why it happens?</p>
  
  <p>Here's the <code>sessionInfo()</code> output:</p>
  
  <pre><code>&gt; sessionInfo()
  R version 3.0.3 (2014-03-06)
  Platform: i386-w64-mingw32/i386 (32-bit)
  
  locale:
  [1] LC_COLLATE=English_United States.1252 
  [2] LC_CTYPE=English_United States.1252   
  [3] LC_MONETARY=English_United States.1252
  [4] LC_NUMERIC=C                          
  [5] LC_TIME=English_United States.1252    
  
  attached base packages:
  [1] stats     graphics  grDevices utils     datasets  methods  
  other attached packages:
  [1] pROC_1.7.1       gdata_2.13.2     TTR_0.22-0                   xts_0.9-7       
  [5] zoo_1.7-11       data.table_1.9.2 nleqslv_2.1.1    plyr_1.8.1      
  
  loaded via a namespace (and not attached):
  [1] grid_3.0.3      gtools_3.3.1    lattice_0.20-27 Rcpp_0.11.1    
  [5] reshape2_1.2.2  stringr_0.6.2 
  </code></pre>