将列名称粘贴到dplyr :: mutate中 [英] Paste in column names into dplyr::mutate

查看:112
本文介绍了将列名称粘贴到dplyr :: mutate中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用dplyr可以轻松地创建一个新列作为其他列的功能

Using dplyr it's easy to create a new column as a function of other columns

library(dplyr)
mutate(iris, Sepal.Length + Sepal.Width)

不幸的是,我有一个我需要的情况将这些列名称粘贴到mutate中。我尝试取消引用字符串,但不起作用:

Unfortunately, I have a situation where I need to paste these column names into mutate. I've tried unquoting the strings but that does not work:

mutate(iris, print("Sepal.Length",quote=FALSE) + print("Sepal.Width",quote=FALSE))  

任何建议将不胜感激。

Any suggestions would be greatly appreciated.

推荐答案

尝试下面:

mutate_(iris, "Sepal.Length + Sepal.Width")

注意_下划线mutate_

Notice _ underscore after mutate_

这篇关于将列名称粘贴到dplyr :: mutate中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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