我正在尝试(并成功)使用以下代码重命名数据框中的多列:
rename_at(c("a", "b", "c"),
funs(paste0(., "_revenue")))
但是,我然后收到此警告:
funs() is soft deprecated as of dplyr 0.8.0
Please use a list of either functions or lambdas:
# Simple named list:
list(mean = mean, median = median)
# Auto named with `tibble::lst()`:
tibble::lst(mean, median)
# Using lambdas
list(~ mean(., trim = .2), ~ median(., na.rm = TRUE))
我尝试查看https://dplyr.tidyverse.org/reference/select_all.html,但看不到任何示例。
请帮助。
答案 0 :(得分:1)
您只需要使用list
而不是funs
并添加lambda样式。
# Before:
funs(name = f(.))
# After:
list(name = ~ f(.))
例如:
> foo <- tibble(a = c(1, 2, 3), b = c(10, 20, 30), c = c(100, 200, 300))
> rename_at(foo, c("a", "b", "c"), list(~ paste0(., "_revenue")))
# A tibble: 3 x 3
a_revenue b_revenue c_revenue
<dbl> <dbl> <dbl>
1 1 10 100
2 2 20 200
3 3 30 300
这里有一个类似的问题:How to change the now deprecated dplyr::funs() which includes an ifelse argument?