Hi I have two data frames with different lengths:
nrow(artdataframe1)
[1] 78
nrow(spdataframe)
[1] 7607
The two data frames have date columns as yyyymmdd
> head(artdataframe1)
artdate artprice
1 19870330 $83.60
2 19871111 $113.60
3 19881128 $78.00
4 19890509 $92.50
5 19890531 $68.00
6 19890801 $115.90
> head(spdataframe)
SP500close SP500date
1 289.20 19870330
2 291.70 19870331
3 292.39 19870401
4 293.63 19870402
5 300.41 19870403
6 301.95 19870406
I would like to join these two dataframes matching by date. It means the lines from artdataframe1 (nrow78) will join to spdataframe (nrow7607). It means there will be a lot of NA values in the ones that do not match which is fine.
I pulled both of these dataframes from the same .csv and already have removed the NA lines in artdataframe1 with
artdataframe1 <- artdataframe[!is.na(artdataframe[,1]),]
So that is some back ground. I tried to use this command but It is not matching per the date as I would expect:
newdf <- merge(spdataframe, artdataframe1, by = intersect(names(SP500date), names(artdate)),
by.spdataframe = by, by.artdataframe1 = by, all = FALSE, all.spdataframe = all, all.artdataframe1 = all,
sort = TRUE, suffixes = c(".spdataframe",".artdataframe1"),
incomparables = NULL)
Any further guidance / assistance would be appreciated.
Thanks
Let me add this, this is the class of each dataframe:
> str(artdataframe1)
'data.frame': 78 obs. of 2 variables:
$ artdate : int 19870330 19871111 19881128 19890509 19890531 19890801 19891127 19891130 19900515 19900517 ...
$ artprice: Factor w/ 74 levels "","$102.10 ",..: 58 10 49 66 36 11 52 69 21 18 ...
> str(spdataframe)
'data.frame': 7607 obs. of 2 variables:
$ SP500close: num 289 292 292 294 300 ...
$ SP500date : int 19870330 19870331 19870401 19870402 19870403 19870406 19870407 19870408 19870409 19870410 ...
They are both integers - will this make a difference when merging?