考虑这个简单的例子:
library(dplyr)
dataframe <- data_frame(helloo = c(1,2,3,4,5,6),
ooooHH = c(1,1,1,2,2,2),
ahaaa = c(200,400,120,300,100,100))
# A tibble: 6 x 3
helloo ooooHH ahaaa
<dbl> <dbl> <dbl>
1 1 1 200
2 2 1 400
3 3 1 120
4 4 2 300
5 5 2 100
6 6 2 100
Run Code Online (Sandbox Code Playgroud)
这里我想将函数ntile应用于包含的所有列oo,但我希望调用这些新列cat+相应的列.
我知道我能做到这一点
dataframe %>% mutate_at(vars(contains('oo')), .funs = funs(ntile(., 2)))
# A tibble: 6 x 3
helloo ooooHH ahaaa
<int> <int> <dbl>
1 1 1 200 …Run Code Online (Sandbox Code Playgroud)