-1

I would like to merge two xts table and respect the columns header, while adding a column if needed. The XTS1 would be :

            ABC DEF
1/18/2020   33  25
1/19/2020   34  26

XTS2 would be :

            ABC DEF GHI
1/20/2020   35  24  19

and the resulting table would be :

            ABC DEF GHI
1/18/2020   33  25  0
1/19/2020   34  26  0
1/20/2020   35  24  19

The order of the column might change. Does anybody has a sharp way of fixing this please ?

Rene Chan
  • 864
  • 1
  • 11
  • 25

1 Answers1

2

Hi please refer below answer hope this will help.

XTS1 <- data.frame('ABC'=c(33,34),'DEF'=c(25,26))
XTS2 <- data.frame('ABC'=c(35),'DEF'=c(24),'GHI'=c(19))

XTS <- merge(XTS1,XTS2,by=c('ABC','DEF'),all=T)
Tushar Lad
  • 490
  • 1
  • 4
  • 17