title: How to create a table by combining every third column?
body: <p>I have data that looks like this:</p>
  
  <pre><code>            SMA    SMA.1      EMA    SMA.2  SMA.1.1    EMA.1
  2016-08-30 1.12411 1.114418 42.50321 100.9875 102.7288 61.25217
  </code></pre>
  
  <p>SMA, SMA.1 and EMA are all calculations done on one type of variable. Let's call it A1. Similarly,SMA.2 SMA.1.1, EMA belong to A2. And this goes on and on until the 29th variable, A29. I want to create a table that looks like:</p>
  
  <pre><code>Var   SMA       SMA.1       EMA
  A1    1.12411   1.114418   42.50321
  A2    100.9875  102.7288   61.25217
  </code></pre>
  
  <p>I've been trying to figure this out for days with a for() function, but it does not work. Here's the dput, if it's helpful:</p>
  
  <pre><code>An ‘xts’ object on 2016-08-30/2016-08-30 containing:
    Data: num [1, 1:87] 1.12 1.11 42.5 100.99 102.73 ...
   - attr(*, "dimnames")=List of 2
    ..$ : NULL
    ..$ : chr [1:87] "SMA" "SMA.1" "EMA" "SMA.2" ...
    Indexed by objects of class: [POSIXct,POSIXt] TZ: 
    xts Attributes:  
   NULL
  &gt; length(new.trend(MergedData))
  [1] 87
  &gt; dput(new.trend(MergedData))
  structure(c(1.12411, 1.114418, 42.5032053202923, 100.9875, 102.7288, 
  61.2521659094113, 1.30729, 1.312984, 48.6820468363914, 0.96929, 
  0.976116, 63.3550259067348, 0.762599999999999, 0.75914, 36.9475885995277, 
  1.29322, 1.301952, 58.0919871676451, 0.72508, 0.717614, 50.7849595338026, 
  8.431315, 8.518538, 60.1081873107905, 8.22937, 8.378464, 56.4004957184729, 
  24.03834, 24.251418, 57.4224323964315, 275.5605, 279.5882, 51.0296673272519, 
  3.7801, 3.814314, 49.384958216963, 3.82987000000001, 3.88755, 
  66.0031408704831, 64.45802, 64.756234, 52.7346708652452, 2.94456, 
  2.979396, 51.219478918934, 13.79045, 13.967152, 73.6027751334041, 
  3.2168, 3.231082, 54.8620717312901, 660.3725, 657.1164, 63.4249734975412, 
  2903.875, 2961.2792, 47.0703023915683, 18.34358, 18.526388, 59.4661365407602, 
  0.7604, 0.7558, 42.3745163443544, 6.65051000000001, 6.660192, 
  62.9781410895429, 13173.25, 13135.84, 73.4189545097276, 66.9848050000001, 
  66.9980439999999, 51.0467264878632, 1111.974, 1120.1316, 52.8805945280585, 
  4.01933, 4.022258, 59.7858956387081, 1.3497, 1.348972, 70.0217831036426, 
  46.48875, 46.79366, 45.2292753580903, 34.6466, 34.816, 37.0539681977138
  ), .Dim = c(1L, 87L), .Dimnames = list(NULL, c("SMA", "SMA.1", 
  "EMA", "SMA.2", "SMA.1.1", "EMA.1", "SMA.3", "SMA.1.2", "EMA.2", 
  "SMA.4", "SMA.1.3", "EMA.3", "SMA.5", "SMA.1.4", "EMA.4", "SMA.6", 
  "SMA.1.5", "EMA.5", "SMA.7", "SMA.1.6", "EMA.6", "SMA.8", "SMA.1.7", 
  "EMA.7", "SMA.9", "SMA.1.8", "EMA.8", "SMA.10", "SMA.1.9", "EMA.9", 
  "SMA.11", "SMA.1.10", "EMA.10", "SMA.12", "SMA.1.11", "EMA.11", 
  "SMA.13", "SMA.1.12", "EMA.12", "SMA.14", "SMA.1.13", "EMA.13", 
  "SMA.15", "SMA.1.14", "EMA.14", "SMA.16", "SMA.1.15", "EMA.15", 
  "SMA.17", "SMA.1.16", "EMA.16", "SMA.18", "SMA.1.17", "EMA.17", 
  "SMA.19", "SMA.1.18", "EMA.18", "SMA.20", "SMA.1.19", "EMA.19", 
  "SMA.21", "SMA.1.20", "EMA.20", "SMA.22", "SMA.1.21", "EMA.21", 
  "SMA.23", "SMA.1.22", "EMA.22", "SMA.24", "SMA.1.23", "EMA.23", 
  "SMA.25", "SMA.1.24", "EMA.24", "SMA.26", "SMA.1.25", "EMA.25", 
  "SMA.27", "SMA.1.26", "EMA.26", "SMA.28", "SMA.1.27", "EMA.27", 
  "SMA.29", "SMA.1.28", "EMA.28")), index = structure(1472533200, tzone = "", tclass = c("POSIXct", 
  "POSIXt")), .indexTZ = "", class = c("xts", "zoo"), .indexCLASS = c("POSIXct", 
  "POSIXt"), tclass = c("POSIXct", "POSIXt"), tzone = "")
  </code></pre>