Mutate a data frame by the mutateTerms. Accepts arbitrary text as mutateTerms to allow forms such as "Sepal.Length >= 2 * Sepal.Width". Terms are vectors or lists of the form "lhs := rhs". Semantics are: terms are evaluated left to right if splitTerms==TRUE (the default).
mutate_se( .data, mutateTerms, ..., splitTerms = TRUE, warn = TRUE, env = parent.frame(), printPlan = FALSE )
.data | data.frame |
---|---|
mutateTerms | character vector of column expressions to mutate by. |
... | force later terms to be bound by name |
splitTerms | logical, if TRUE into separate mutates (if FALSE instead, pass all at once to dplyr). |
warn | logical, if TRUE warn about name re-use. |
env | environment to work in. |
printPlan | logical, if TRUE print the expression plan. |
.data with altered columns.
Note: this method as the default setting splitTerms = TRUE
, which is
safer (avoiding certain known dplyr
/dblyr
issues)
(please see the side-notes of https://winvector.github.io/FluidData/partition_mutate.html for some references).
limit <- 3.5 datasets::iris %.>% mutate_se(., qae(Sepal_Long = Sepal.Length >= 2 * Sepal.Width, Petal_Short := Petal.Length <= limit)) %.>% head(.)#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species Sepal_Long #> 1 5.1 3.5 1.4 0.2 setosa FALSE #> 2 4.9 3.0 1.4 0.2 setosa FALSE #> 3 4.7 3.2 1.3 0.2 setosa FALSE #> 4 4.6 3.1 1.5 0.2 setosa FALSE #> 5 5.0 3.6 1.4 0.2 setosa FALSE #> 6 5.4 3.9 1.7 0.4 setosa FALSE #> Petal_Short #> 1 TRUE #> 2 TRUE #> 3 TRUE #> 4 TRUE #> 5 TRUE #> 6 TRUE