取消符号引用 [英] Unquoting of symbols

查看:67
本文介绍了取消符号引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看dplyr中rename()函数的文档,发现了一些有趣的东西。他们有不对符号加引号的概念,但我想我并没有从示例中掌握这个想法。

I was going through the documentation of rename() function in dplyr and found something interesting. They had this concept of unquoting of symbol, but I think I didn't quit grasp the idea from the example.

library(dplyr)

vars <- c(var1 = "cyl", var2 ="am")
select(mtcars, !!vars)

然后他们有了 !!! vars tidyverse

是吗只需选择这两列就可以了,或者如此特殊。如果不是,为什么要使用它呢?

Is it just selecting those two columns and that's it or something special going on. If not, why bother using it?

推荐答案

select 函数支持字符串,符号作为输入参数。当我们有更多变量时,使用 !!!

The select function supports strings, symbols as input arguments. When we have more variables, the !!! is used

select(mtcars, !!!vars)

不同之处在于,这里还将列名重命名为'var1','var2',而在另一种情况下,它会剥离名称

The difference is that here it will also rename the column names to 'var1', 'var2' while in the other case it is stripping off the names

这篇关于取消符号引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆