在dplyr中按mutate_at中的名称排除列 [英] Exclude columns by names in mutate_at in dplyr

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

问题描述

我正在尝试做一些非常简单的事情,但是却找不到正确的指定方法。我只是想从 mutate_at 中排除一些命名列。如果我指定位置,效果很好,但是我不想硬编码位置。

I am trying to do something very simple, and yet can't figure out the right way to specify. I simply want to exclude some named columns from mutate_at. It works fine if I specify position, but I don't want to hard code positions.

例如,我想要这样的输出:

For example, I want the same output as this:

mtcars %>% mutate_at(-c(1, 2), max)

但是,通过指定 mpg cyl 列名

我尝试了很多事情,包括:

I tried many things, including:

mtcars %>% mutate_at(-c('mpg', 'cyl'), max)

是否有 mutate_at 中使用名称和排除的方法?

Is there a way to work with names and exclusion in mutate_at?

推荐答案

使用 vars 指定列,其作用方式与 select()相同,并允许您使用-

You can use vars to specify the columns, which works the same way as select() and allows you to exclude columns using -:

mtcars %>% mutate_at(vars(-mpg, -cyl), max)

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

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