1. mutate_when(.data, when, ..., by)
  2. 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.
  1. #mutate_dt
  2. # 增添一列名为one,内容全为1;同时,让所有的Sepal.Length列数值加1
  3. iris %>% mutate_dt(one = 1,Sepal.Length = Sepal.Length + 1)
  4. #如果只想要新增列,可以使用transmute_dt函数
  5. iris %>% transmute_dt(one = 1,Sepal.Length = Sepal.Length + 1)
  6. #有条件的新增列
  7. iris[3:8,] %>%
  8. mutate_when(Petal.Width == .2, #当Petal.Width = .2时
  9. one = 1,Sepal.Length=2) #one列全是1,Sepal.Length=2
  10. #pe开头的字段全部标准化操作
  11. iris %>% mutate_vars("Pe",scale)
  12. #数值型字段全部标准化操作
  13. iris %>% mutate_vars(is.numeric,scale)
  14. iris %>% mutate_vars(-is.factor,scale)
  15. #1:2列标准化操作
  16. iris %>% mutate_vars(1:2,scale)
  17. #全部列
  18. iris %>% mutate_vars(.func = as.character)