我正在查看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
更多推荐
取消符号引用
发布评论