I'm struggling with joining two data sets
result <- left_join(df1, df2, by="id")
Error: cannot join on columns 'id' x 'id':
Can't join on 'id' x 'id' because of
incompatible types (factor / integer)
df1$id <- as.integer (df1$id)
From help page:
as.numeric(levels(f))[f] is recommended instead of
The issue with factor => numeric/integer conversion has been comprehensively answered by @Joshua Ulrich here.
Seek and ye shall find but user needs to know what to look for to reach the answer.
The Warning message in documentation for
The interpretation of a factor depends on both the codes and the "levels" attribute. Be careful only to compare factors with the same set of levels (in the same order). In particular, as.numeric applied to a factor is meaningless, and may happen by implicit coercion. To transform a factor f to approximately its original numeric values, as.numeric(levels(f))[f] is recommended and slightly more efficient than as.numeric(as.character(f)).
This step could be avoided by ensuring
stringsAsFactors=FALSE while reading input data to side-step conversion of character variables to factors unless they are absolutely essential i.e. when
levels of factors are required in analysis.