mutate_when(.data, when, ..., by)
mutate_vars(.data, .cols = NULL, .func, ..., by)
Arguments
.data |
data.frame |
when |
An object which can be coerced to logical mode |
… |
Name-value pairs of expressions for mutate_when . Additional parameters to be passed to parameter ‘.func’ in mutate_vars . |
by |
(Optional) Mutate by what group? |
.cols |
Any types that can be accepted by [select_dt](https://hope-data-science.github.io/tidyfst/reference/select.html) . |
.func |
Function to be run within each column, should return a value or vectors with same length. |
#mutate_dt
# 增添一列名为one,内容全为1;同时,让所有的Sepal.Length列数值加1
iris %>% mutate_dt(one = 1,Sepal.Length = Sepal.Length + 1)
#如果只想要新增列,可以使用transmute_dt函数
iris %>% transmute_dt(one = 1,Sepal.Length = Sepal.Length + 1)
#有条件的新增列
iris[3:8,] %>%
mutate_when(Petal.Width == .2, #当Petal.Width = .2时
one = 1,Sepal.Length=2) #one列全是1,Sepal.Length=2
#pe开头的字段全部标准化操作
iris %>% mutate_vars("Pe",scale)
#数值型字段全部标准化操作
iris %>% mutate_vars(is.numeric,scale)
iris %>% mutate_vars(-is.factor,scale)
#1:2列标准化操作
iris %>% mutate_vars(1:2,scale)
#全部列
iris %>% mutate_vars(.func = as.character)