I'm encountering an error where I try to join two data frames using the dplyr join functions by two Date columns. This is the error I get:
Error: cannot join on columns 'DateInfo' x 'DateInfo': Can't join on 'DateInfo' x 'DateInfo' because of incompatible types (Date / Date)
The base merge
function works fine and I can't seem to find an example of what could be causing this through googling or other stack overflow questions.
The problem is I can't create a reproducible example and the data I am using I can't share. For example this works with no problems:
d1 <- data_frame(Num = 1:5, DateInfo = as.Date(c("2014-01-03", "2014-04-05", "2015-01-03", "2014-04-02", "2011-07-28"), format = "%Y-%m-%d"))
d2 <- data_frame(Name = c("a", "b", "c", "d", "e"), DateInfo = as.Date(c("2014-01-03", "2014-04-05", "2015-01-03", "2014-04-02", "2011-07-28"), format = "%Y-%m-%d"))
d3 <- left_join(d1, d2, by = c("DateInfo" = "DateInfo"))
Has anyone had any experience with not being able to join on two columns that are, as far as the class
function is concerned, are the same type but still getting this error?
EDIT: Just to get this out of the way I can get around this error by using merge or converting the dates to characters and then joining, so I'm really just interested in why dplyr
would tell me I can't merge on two columns with the same type.
dplyr
anddata.table
support POSIXlt – scribbles Aug 18 '15 at 20:43d1
andd2
data frames in my example. – Matt Mills Aug 18 '15 at 20:46as.Date
function in r stores them as numeric, so you are unable to merge them. Some of my data was originally pulled from a postgresql DB so that may be what is the problem here. – Matt Mills Aug 18 '15 at 20:53