Skip to content

Commit b18cd4c

Browse files
committed
use filter()
1 parent 17a7be5 commit b18cd4c

File tree

1 file changed

+9
-27
lines changed

1 file changed

+9
-27
lines changed

docs/src/man/filter.md

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ be set as `all` or `any`, and supply the conditions by using the `by` keyword op
1313

1414
The main feature of `byrow(ds, fun, cols, by = ...)` when `fun` is `all/any` is that the `by` keyword argument can be a vector of functions. Thus, when a multiple columns are supplied as `cols` each column can have its own `by`.
1515

16+
### `filter` and `filter!`
17+
18+
The `filter` and `filter!` functions are two shortcuts for doing the `byrow` and `getindex` operations at the same call.
19+
20+
`filter(ds, cols; [type = all, by = isequal(true),...])` is the shortcut for `ds[byrow(ds, type, cols; by = by,...), :]`, and `filter!(ds, cols; [type = all, by = isequal(true),...])` is the shortcut for `deleteat![ds, byrow(ds, type, cols; by = by,...))`.
21+
1622
### Examples
1723

1824
The first expression creates a data set, and in the second one we use `byrow` to filter `all` rows which the values of all columns are equal to 1.
@@ -53,20 +59,8 @@ Note that only the first row is meeting the condition. As another example, let's
5359
filter all rows which the numbers in all columns are odd.
5460

5561
```jldoctest
56-
julia> _tmp = byrow(ds, all, :, by = isodd)
57-
10-element Vector{Bool}:
58-
1
59-
0
60-
1
61-
0
62-
1
63-
0
64-
1
65-
0
66-
1
67-
0
62+
julia> filter(ds, :, by = isodd)
6863
69-
julia> ds[_tmp, :]
7064
5×3 Dataset
7165
Row │ x1 x2 x3
7266
│ identity identity identity
@@ -133,20 +127,8 @@ julia> modify!(ds, 2:3 .=> (x -> x .> mean(x)) .=> [:_tmp1, :_tmp2])
133127
9 │ 1 9 1 true false
134128
10 │ 1 10 2 true true
135129
136-
julia> _tmp = byrow(ds, all, r"_tm")
137-
10-element Vector{Bool}:
138-
0
139-
0
140-
0
141-
0
142-
0
143-
1
144-
0
145-
1
146-
0
147-
1
130+
julia> filter(ds, r"_tm") # translate to ds[byrow(ds, all, r"_tm"), :]
148131
149-
julia> ds[_tmp, :]
150132
3×5 Dataset
151133
Row │ x1 x2 x3 _tmp1 _tmp2
152134
│ identity identity identity identity identity
@@ -244,7 +226,7 @@ Row │ x1 x2 x3
244226
9 │ true false false
245227
10 │ false false false
246228
247-
julia> ds[byrow(_tmp, any, :), :] # use the result of previous run
229+
julia> filter(_tmp, :, type = any) # OR ds[byrow(_tmp, any, :), :]. This uses the result of previous run
248230
5×3 Dataset
249231
Row │ x1 x2 x3
250232
│ identity isodd identity

0 commit comments

Comments
 (0)