Reshape data obtained using TriMatch package in R to another data keeping matched triplets serial ID for further analysis

89 Views Asked by At

How can I reshape data A (obtained using TriMatch package in R) to data B and keep matched triplets serial ID to allow further analysis?

Used code to get data A and its structure:

formu <- ~ Age+FEMALE+renal_insuf+Diabetes+MI+LVEF_pre+ Crea+ NYHA+treated_Hypertension +  PVD+CVA +PTCA+ offpump+ngrafts+TRIAL 
#======================================================================================================================
library(TriMatch)
tpsa <- trips(data, data$conduit, formu) #tpsa the results from trips=Estimates propensity scores for three groups
data1.matched <- trimatch(tpsa)
matched.out <- merge(data1.matched, data)
str( matched.out)

###################
data.frame':    1776 obs. of  67 variables:
 $ BITA                          : chr  "3947" "7787" "8334" "3954" ...
 $ LITA+RA                       : chr  "9405" "4711" "7486" "6660" ...
 $ LITA+SVG                      : chr  "4440" "9216" "8683" "5432" ...
 $ 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 "LITA+SVG","BITA",..: 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 "LITA+SVG","BITA",..: 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 "LITA+SVG","BITA",..: 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 ...

Data B struture:


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  "BITA" "BITA" "BITA" "BITA" ...
 $ 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  "CORONARY" "PREVENT-IV" "PREVENT-IV" "CORONARY" ...

Any advice will be greatly appreciated.

0

There are 0 best solutions below