取消符号引用

编程入门 行业动态 更新时间:2024-10-24 09:28:17
本文介绍了取消符号引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在查看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

更多推荐

取消符号引用

本文发布于:2023-11-12 20:38:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582477.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:符号

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!