I'm struggling with joining two data sets
#df1
id name1
1 a
2 b
3 c
and
$df2
id name2
1 c
2 d
I try to join them by their id
library(dplyr)
result <- left_join(df1, df2, by="id")
it gives me the following error
Error: cannot join on columns 'id' x 'id': Can't join on 'id' x 'id' because of incompatible types (factor / integer)
because they have different classes:
sapply(df1, class)
id name1
"factor" "factor"
sapply(df2, class)
id name2
"integer" "factor"
I tried to change the classes to make them similar
df1$id <- as.integer (df1$id)
but , it doesn't help to find the common rows in two datasets. ( it can not recognize similar "id"s in df2)