title: Format and export the output of Mann-Kendall test in R to excel from Rstudio
body: <p>I've just started using R and would like to use the <code>trend</code> package to perform <code>Mann-Kendall</code> tests on yearly groundwater level data of multiple wells. Here is a sample from my dataframe <code>pri.csv</code>:</p>
  
  <pre><code>dput(head(GL, 10))
  structure(list(WLCODE = structure(c(8L, 5L, 3L, 6L, 1L, 7L, 18L, 
  19L, 20L, 22L), .Label = c("W04039", "W04295", "W04299", "W04790", 
  "W04791", "W04797", "W04799", "W04824", "W25293", "W25298", "W25355", 
  "W25385", "W25404", "W25438", "W25445", "W25451", "W25476", "W25596", 
  "W25598", "W25599", "W25600", "W25612", "W25697", "W31151", "W31152"
  ), class = "factor"), YEAR_OBS = c(2018L, 2018L, 2018L, 2018L, 
  2018L, 2018L, 2018L, 2018L, 2018L, 2018L), POMRB = c(4.14, 9.05, 
  8.87, 2.3, 6.05, 3.6, 2.05, 4.27, 7.9, 8.4)), .Names = c("WLCODE", 
  "YEAR_OBS", "POMRB"), row.names = c(NA, 10L), class = "data.frame")
  </code></pre>
  
  <p>Here is what I've done so far:</p>
  
  <pre><code>mydata&lt;-read.csv("pri.csv")
  sp &lt;- split(mydata, mydata$WLCODE)
  results_list &lt;- lapply(sp, function(mydata){
    tryCatch(mk.test(mydata[, 3]),
             error = function(e) e)
  })
  bad &lt;- sapply(results_list, inherits, "error")
  results_list[!bad]
  </code></pre>
  
  <h1>Output</h1>
  
  <pre><code>$W07792
  
      Mann-Kendall trend test
  
  data:  DF[, 3]
  z = 1.0355, n = 16, p-value = 0.3004
  alternative hypothesis: true S is not equal to 0
  sample estimates:
         S     varS      tau 
   24.0000 493.3333   0.2000 
  
  
  $W07793
  
      Mann-Kendall trend test
  
  data:  DF[, 3]
  z = -0.68205, n = 20, p-value = 0.4952
  alternative hypothesis: true S is not equal to 0
  sample estimates:
            S        varS         tau 
  -22.0000000 948.0000000  -0.1164037
  </code></pre>
  
  <p>I want to produce a table using this output and export it to excel with <code>WLCODE</code> in each row and <code>Z</code>, <code>p-value</code>, <code>S</code>, <code>varS</code>, <code>tau</code> value in columns. How can I do that? Please help.</p>