join其中同名字段在一个df中是整数而在另一个

时间:2017-09-02 17:16:01

标签: r dplyr

glimpse(df1)
Observations: 10,772,215
Variables: 5
$ id                 <dbl> 17947442, 11919813, 11919814, ..
$ category_id        <int> 22, 6, 11, ...

glimpse(df2)
Observations: 3,000,000
Variables: 5
$ id                 <chr> "17947442", "11919813", "11919814", ..
$ blah        <int>  1, 2, 3, ...

我想在id上加入df1和df2但是id在每个中都是不同的类型(dbl与chr)。

尝试:

> newdf <- df1 %>% inner_join(df2, by = c(as.character(id), id))
Error in as.character(id) : 
  cannot coerce type 'closure' to vector of type 'character'

然后

newdf <- df1 %>% inner_join(df2, by = "id")
Error in as.character(id) : 
  cannot coerce type 'closure' to vector of type 'character'

然后

newdf <- df1 %>% inner_join(df2, by = c(as.character(.$id), "id"))
Error in inner_join_impl(x, y, by$x, by$y, suffix$x, suffix$y, check_na_matches(na_matches)) : Can't join on 'id' x 'id' because of incompatible types (numeric / character)

我如何加入这些? (最好使用dplyr join)

0 个答案:

没有答案