With DataFrames 1.3, it’s now possible to mutate subsets of DataFrames. The normal approach looks like this:

```
df = DataFrame(x = 1:5, y = [2, 4, 6, missing, 10])
sdf = subset(df, :y => ByRow(ismissing), view = true)
transform!(sdf, :x => ByRow(x -> 2x) => :y)
df
```

Because this is a multi-step approach it doesn’t work well with piping / Chain.jl, so it’s natural to introduce some kind of special macro solution for DataFrameMacros.jl v0.2. I’ve iterated back and forth on this and now decided on an optional `@subset`

argument to `@transform!`

and `@select!`

. (The `@subset`

expression by itself could not be executed without a DataFrame argument, so this only works within `@transform!`

and `@select!`

)

## Example

```
julia> df = DataFrame(x = 1:5, y = [2, 4, 6, missing, 10])
5×2 DataFrame
Row │ x y
│ Int64 Int64?
─────┼────────────────
1 │ 1 2
2 │ 2 4
3 │ 3 6
4 │ 4 missing
5 │ 5 10
julia> @transform!(df, @subset(ismissing(:y)), :y = 2 * :x)
5×2 DataFrame
Row │ x y
│ Int64 Int64?
─────┼───────────────
1 │ 1 2
2 │ 2 4
3 │ 3 6
4 │ 4 8
5 │ 5 10
julia> @transform!(df, @subset(:x >= 3), :z = :y + :x)
5×3 DataFrame
Row │ x y z
│ Int64 Int64? Int64?
─────┼────────────────────────
1 │ 1 2 missing
2 │ 2 4 missing
3 │ 3 6 9
4 │ 4 8 12
5 │ 5 10 15
# the flag macros like `@c` for column-wise mode also work as usual
julia> @transform!(df, @subset(@c :x .< sum(:x) / length(:x)), :y = 0)
5×3 DataFrame
Row │ x y z
│ Int64 Int64? Int64?
─────┼────────────────────────
1 │ 1 0 missing
2 │ 2 0 missing
3 │ 3 6 9
4 │ 4 8 12
5 │ 5 10 15
```