mutate_cond: mutate cond

Description Usage Arguments Details Author(s) Examples

Description

mutate acting only on the rows satisfying the condition

Usage

1
2
mutate_cond(.data, condition, ..., envir = parent.frame(), 
    na.rmCond = FALSE)

Arguments

.data

data.frame to be modified

condition

condition for selecting rows to be modified

...

further arguments to mutate

envir

the frame where the condition is evaluated

na.rmCond

set to TRUE to set NA values in cond to FALSE. By default an error is thrown

Details

condition is evaluated in .data inside the parent frame. Hence column names can be used. .data refers to the subset group of the data.frame processed.

Author(s)

Thomas Wutzler

Examples

1
2
3
4
5
6
7
8
9
if (require(dplyr)) {
  ans <- iris %>%
    mutate_cond(
      Species == "setosa"
      , Petal.Length = 1.0
    )
  ans %>% filter(Species == "setosa") %>% select(Petal.Length) %>% head() # 1.0
  ans %>% filter(Species != "setosa") %>% select(Petal.Length) %>% head() # orig
}

bgctw/dplyrUtil documentation built on Nov. 11, 2020, 12:25 a.m.