【发布时间】:2018-10-20 01:51:54
【问题描述】:
我想知道基于不一致列合并数据集的最简洁的方法。
> head(team_measures)
# A tibble: 6 x 7
team_id geo_entropy job_entropy
<chr> <dbl> <dbl>
1 10012 1.79 1.79
2 10027 0 1.25
3 10044 1.79 0.650
4 10049 1.00 1.46
5 10053 0.811 2.00
> head(p_calc)
# A tibble: 6 x 2
team.id p_average
<int> <dbl>
1 10000 4.75
2 10001 4.98
3 10002 4.17
4 10003 4.32
5 10004 4.22
6 10005 4.44
我目前正在做这样一个简单的程序感到非常笨拙的事情:
team_measures <- p_calc %>%
rename(team_id = team.id) %>%
select(team_id, p_average) %>%
left_join(team_measures, by = c('team_id')) %>%
na.omit()
实际上比这更糟糕,因为我得到了错误:
Error in left_join_impl(x, y, by_x, by_y, aux_x, aux_y, na_matches) : Can't join on 'team_id' x 'team_id' because of incompatible types (character / integer)
所以我必须将它们重铸为相同的类型。
有没有更简单的方法来实现这一点?
【问题讨论】: