1

I have these two dataframes that are examples of two different larger dataframes:

>df1
     V1            V2     V3
4462 2010-03-20    0      A
4463 2010-03-21    0      A
4464 2010-03-22    0      A
4465 2010-03-23    0,7    A
4466 2010-03-24    8      A

and

>df2     
     X1           X2            X3
3670 2010-03-20   2.840747e+00   0.0000000
3671 2010-03-21   1.223321e+01   0.0000000
3672 2010-03-22   9.924097e-01   1.3000000
3673 2010-03-24   1.149400e+01   0.0000000

As you might have seen already the date: "2010-03-23" in column df2[,X1] is missing in contrary to column df1[,V1].

However I still want to bind these date frames into a new date frame (df3), e.g. as stated below according to date:

     Y1           Y2     Y3  Y4             Y5             
1    2010-03-20   0      A   2.840747e+00   0.0000000
2    2010-03-21   0      A   1.223321e+01   0.0000000
3    2010-03-22   0      A   9.924097e-01   1.3000000
4    2010-03-23   0,7    A   NA             NA
5    2010-03-24   8      A   1.149400e+01   0.0000000

I cannot get it to work with cbind because of the different number of rows. Does anyone know how to do this? Help would be much appreciated!

4

1 回答 1

1
merge(df1,df2,by.x="V1",by.y="X1",all=TRUE)

#           V1  V2 V3         X2  X3
# 1 2010-03-20   0  A  2.8407470 0.0
# 2 2010-03-21   0  A 12.2332100 0.0
# 3 2010-03-22   0  A  0.9924097 1.3
# 4 2010-03-23 0,7  A         NA  NA
# 5 2010-03-24   8  A 11.4940000 0.0
于 2013-04-30T15:06:01.010 回答