title: Reshape data obtained using TriMatch package in R to another data keeping matched triplets serial ID for further analysis
body: <p>How can I reshape data A (obtained using <code>TriMatch</code> package in <code>R</code>) to data B and keep matched triplets serial ID to allow further analysis?</p>
  <p>Used code to get data A and its structure:</p>
  <pre><code>formu &lt;- ~ Age+FEMALE+renal_insuf+Diabetes+MI+LVEF_pre+ Crea+ NYHA+treated_Hypertension +  PVD+CVA +PTCA+ offpump+ngrafts+TRIAL 
  #======================================================================================================================
  library(TriMatch)
  tpsa &lt;- trips(data, data$conduit, formu) #tpsa the results from trips=Estimates propensity scores for three groups
  data1.matched &lt;- trimatch(tpsa)
  matched.out &lt;- merge(data1.matched, data)
  str( matched.out)
  
  ###################
  data.frame':    1776 obs. of  67 variables:
   $ BITA                          : chr  &quot;3947&quot; &quot;7787&quot; &quot;8334&quot; &quot;3954&quot; ...
   $ LITA+RA                       : chr  &quot;9405&quot; &quot;4711&quot; &quot;7486&quot; &quot;6660&quot; ...
   $ LITA+SVG                      : chr  &quot;4440&quot; &quot;9216&quot; &quot;8683&quot; &quot;5432&quot; ...
   $ D.m3                          : num  0.000877 0.000227 0.001541 0.000446 0.000854 ...
   $ D.m2                          : num  0.000481 0.001296 0 0.000515 0.001079 ...
   $ D.m1                          : num  9.84e-05 1.49e-04 1.67e-04 9.69e-04 2.29e-04 ...
   $ Dtotal                        : num  0.00146 0.00167 0.00171 0.00193 0.00216 ...
   $ BITA.Serial.ID                : num  4709 9000 9596 4716 2401 ...
   $ BITA.conduit                  : Factor w/ 3 levels &quot;LITA+SVG&quot;,&quot;BITA&quot;,..: 2 2 2 2 2 2 2 2 2 2 ...
   $ BITA.Age                      : num  66 42 65 65 71.6 ...
   $ BITA.FEMALE                   : num  1 0 1 0 0 0 0 0 0 0 ...
   $ BITA.renal_insuf              : num  0 0 0 0 0 0 0 0 0 0 ...
   $ BITA.Diabetes                 : num  1 0 0 1 0 0 1 0 0 0 ...
   $ BITA.MI                       : num  1 1 1 1 0 0 0 0 0 0 ...
   $ BITA.LVEF_pre                 : num  1 1 1 1 0 1 1 1 1 1 ...
   $ BITA.BMI                      : num  26.6 43.9 37.1 30.5 24.9 ...
   $ BITA.Crea                     : num  53.1 79.6 79.6 123.8 103 ...
   $ BITA.NYHA                     : num  0 1 0 0 0 1 1 0 0 0 ...
   $ BITA.treated_Hypertension     : num  1 1 1 1 1 0 1 0 1 1 ...
   $ BITA.treated_Hyperlipaemia    : num  0 0 1 1 1 0 0 1 1 1 ...
   $ BITA.PVD                      : num  0 0 0 1 0 0 0 0 0 0 ...
   $ BITA.CVA                      : num  0 0 0 0 0 0 0 1 0 0 ...
   $ BITA.PTCA                     : num  0 1 0 1 0 0 0 0 0 0 ...
   $ BITA.AF_pre                   : num  0 0 0 0 0 0 0 0 0 0 ...
   $ BITA.offpump                  : num  1 0 1 0 1 0 0 1 1 1 ...
   $ BITA.ngrafts                  : num  4 4 5 4 3 4 3 3 4 2 ...
   $ BITA.TRIAL                    : num  2 4 4 2 1 4 2 2 2 2 ...
   $ LITA+RA.Serial.ID             : num  10772 5535 8678 7754 1734 ...
   $ LITA+RA.conduit               : Factor w/ 3 levels &quot;LITA+SVG&quot;,&quot;BITA&quot;,..: 3 3 3 3 3 3 3 3 3 3 ...
   $ LITA+RA.Age                   : num  60 60 61 79 74.1 ...
   $ LITA+RA.FEMALE                : num  0 0 0 0 0 1 1 1 1 0 ...
   $ LITA+RA.renal_insuf           : num  0 0 0 0 0 0 0 0 0 0 ...
   $ LITA+RA.Diabetes              : num  0 1 0 1 0 0 1 0 0 1 ...
   $ LITA+RA.MI                    : num  1 1 1 1 0 0 0 0 0 0 ...
   $ LITA+RA.LVEF_pre              : num  0 1 1 1 0 1 1 1 1 1 ...
   $ LITA+RA.BMI                   : num  26.1 25 28.5 36.5 27.4 ...
   $ LITA+RA.Crea                  : num  79.6 79.6 79.6 98 82 ...
   $ LITA+RA.NYHA                  : num  0 0 0 1 0 0 1 0 0 1 ...
   $ LITA+RA.treated_Hypertension  : num  0 1 1 1 0 1 0 1 1 1 ...
   $ LITA+RA.treated_Hyperlipaemia : num  1 1 1 1 1 1 1 0 1 1 ...
   $ LITA+RA.PVD                   : num  0 0 0 0 0 1 0 0 0 1 ...
   $ LITA+RA.CVA                   : num  0 0 0 0 0 1 0 0 0 0 ...
   $ LITA+RA.PTCA                  : num  0 0 0 0 1 0 0 0 0 0 ...
   $ LITA+RA.AF_pre                : num  0 0 1 0 0 0 0 0 0 0 ...
   $ LITA+RA.offpump               : num  1 1 0 1 1 0 1 1 1 1 ...
   $ LITA+RA.ngrafts               : num  3 3 4 3 2 4 2 4 3 2 ...
   $ LITA+RA.TRIAL                 : num  4 2 4 2 1 4 2 2 2 2 ...
   $ LITA+SVG.Serial.ID            : num  5250 10571 9971 6360 2846 ...
   $ LITA+SVG.conduit              : Factor w/ 3 levels &quot;LITA+SVG&quot;,&quot;BITA&quot;,..: 1 1 1 1 1 1 1 1 1 1 ...
   $ LITA+SVG.Age                  : num  73 51 61 63 54.1 ...
   $ LITA+SVG.FEMALE               : num  0 0 0 0 1 0 1 0 0 1 ...
   $ LITA+SVG.renal_insuf          : num  0 0 0 0 0 0 0 0 0 0 ...
   $ LITA+SVG.Diabetes             : num  0 1 0 1 0 0 0 1 1 1 ...
   $ LITA+SVG.MI                   : num  1 0 1 0 0 1 0 0 1 0 ...
   $ LITA+SVG.LVEF_pre             : num  1 0 1 1 0 1 1 1 1 1 ...
   $ LITA+SVG.BMI                  : num  20.2 27 27.1 29.4 26.6 ...
   $ LITA+SVG.Crea                 : num  97.3 106.1 79.6 106.1 97.2 ...
   $ LITA+SVG.NYHA                 : num  0 0 0 1 0 1 0 0 1 1 ...
   $ LITA+SVG.treated_Hypertension : num  0 1 1 1 0 1 1 1 1 1 ...
   $ LITA+SVG.treated_Hyperlipaemia: num  1 1 1 1 1 0 1 1 1 1 ...
   $ LITA+SVG.PVD                  : num  0 0 0 1 0 0 0 1 0 0 ...
   $ LITA+SVG.CVA                  : num  0 0 0 0 0 0 0 0 0 0 ...
   $ LITA+SVG.PTCA                 : num  0 0 0 0 0 0 0 0 0 0 ...
   $ LITA+SVG.AF_pre               : num  0 0 0 1 0 0 0 0 0 0 ...
   $ LITA+SVG.offpump              : num  0 0 0 1 0 0 0 0 0 1 ...
   $ LITA+SVG.ngrafts              : num  2 5 4 2 2 3 3 3 2 3 ...
   $ LITA+SVG.TRIAL                : num  2 4 4 2 1 4 2 2 2 2 ...
  
  </code></pre>
  <p>Data B struture:</p>
  <pre><code>
  Classes ‘data.table’ and 'data.frame':  5328 obs. of  32 variables:
   $ Serial.ID            : int  4709 9000 9596 4716 2401 8978 7460 4974 4704 3929 ...
   $ conduit              : chr  &quot;BITA&quot; &quot;BITA&quot; &quot;BITA&quot; &quot;BITA&quot; ...
   $ Age                  : num  66 42 65 65 71.6 ...
   $ FEMALE               : int  1 0 1 0 0 0 0 0 0 0 ...
   $ renal_insuf          : int  0 0 0 0 0 0 0 0 0 0 ...
   $ Diabetes             : int  1 0 0 1 0 0 1 0 0 0 ...
   $ MI                   : int  1 1 1 1 0 0 0 0 0 0 ...
   $ LVEF_pre             : int  1 1 1 1 0 1 1 1 1 1 ...
   $ BMI                  : num  26.6 43.9 37.1 30.5 24.9 ...
   $ Crea                 : num  53.1 79.6 79.6 123.8 103 ...
   $ NYHA                 : int  0 1 0 0 0 1 1 0 0 0 ...
   $ treated_Hypertension : int  1 1 1 1 1 0 1 0 1 1 ...
   $ treated_Hyperlipaemia: int  0 0 1 1 1 0 0 1 1 1 ...
   $ PVD                  : int  0 0 0 1 0 0 0 0 0 0 ...
   $ CVA                  : int  0 0 0 0 0 0 0 1 0 0 ...
   $ PTCA                 : int  0 1 0 1 0 0 0 0 0 0 ...
   $ AF_pre               : int  0 0 0 0 0 0 0 0 0 0 ...
   $ offpump              : int  1 0 1 0 1 0 0 1 1 1 ...
   $ ngrafts              : int  4 4 5 4 3 4 3 3 4 2 ...
   $ TRIAL                : chr  &quot;CORONARY&quot; &quot;PREVENT-IV&quot; &quot;PREVENT-IV&quot; &quot;CORONARY&quot; ...
  
  </code></pre>
  <p><strong>Any advice will be greatly appreciated.</strong></p>