在dplyrs left_join中使用内部变量内的值
我有一个这样的变量:
name = "ID"
并且我想使用值(“ id” )将数据框架加入一个这样的数据:
left_join(df1, df2, by=c(name = "col_to_join")
我再次不知道该怎么做:/
但是 小例子
a = mtcars %>%
select(1:3)
b = mtcars %>%
select(3:5)
var_to_join = "disp"
# i know this could be done by just "disp"
# But the question is more on how to use a variable inside the by-argument
left_join(a, b, by = c(var_to_join = "disp"))
I have a variable like this:
name = "ID"
and i want to use the value ("ID"
) to join a dataframe to another like this:
left_join(df1, df2, by=c(name = "col_to_join")
but I again don't know how to do this :/
with a little example
a = mtcars %>%
select(1:3)
b = mtcars %>%
select(3:5)
var_to_join = "disp"
# i know this could be done by just "disp"
# But the question is more on how to use a variable inside the by-argument
left_join(a, b, by = c(var_to_join = "disp"))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
stats :: SetNames()
或rlang :: set_names()
创建一个命名vector:You can use
stats::setNames()
orrlang::set_names()
to create a named vector: