You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/docstrings.jl
+64Lines changed: 64 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3316,3 +3316,67 @@ julia> @chain df begin
3316
3316
15 │ e 15 45 30
3317
3317
```
3318
3318
"""
3319
+
3320
+
const docstring_relocate =
3321
+
"""
3322
+
@relocate(df, columns, before = nothing, after = nothing)
3323
+
3324
+
Rearranges the columns of a data frame. This function allows for moving specified columns to a new position within the data frame, either before or after a given target column. The `columns`, `before`, and `after` arguments all accept tidy selection functions. Only one of `before` or `after` should be specified. If neither are specified, the selected columns will be moved to the beginning of the data frame.
3325
+
3326
+
# Arguments
3327
+
- `df`: The data frame.
3328
+
- `columns`: Column or columns to to be moved.
3329
+
- `before`: (Optional) Column or columns before which the specified columns will be moved. If not provided or `nothing`, this argument is ignored.
3330
+
- `after`: (Optional) Column or columns after which the specified columns will be moved. If not provided or `nothing`, this argument is ignored.
3331
+
3332
+
# Examples
3333
+
```jldoctest
3334
+
julia> df = DataFrame(A = 1:5, B = 6:10, C = ["A", "b", "C", "D", "E"], D = ['A', 'B','A', 'B','C'],
3335
+
E = 1:5, F = ["A", "b", "C", "D", "E"]);
3336
+
3337
+
julia> @relocate(df, where(is_string), before = where(is_integer))
3338
+
5×6 DataFrame
3339
+
Row │ C F A B E D
3340
+
│ String String Int64 Int64 Int64 Char
3341
+
─────┼───────────────────────────────────────────
3342
+
1 │ A A 1 6 1 A
3343
+
2 │ b b 2 7 2 B
3344
+
3 │ C C 3 8 3 A
3345
+
4 │ D D 4 9 4 B
3346
+
5 │ E E 5 10 5 C
3347
+
3348
+
3349
+
julia> @relocate(df, B, C, D, after = E)
3350
+
5×6 DataFrame
3351
+
Row │ A E B C D F
3352
+
│ Int64 Int64 Int64 String Char String
3353
+
─────┼───────────────────────────────────────────
3354
+
1 │ 1 1 6 A A A
3355
+
2 │ 2 2 7 b B b
3356
+
3 │ 3 3 8 C A C
3357
+
4 │ 4 4 9 D B D
3358
+
5 │ 5 5 10 E C E
3359
+
3360
+
julia> @relocate(df, B, C, D, after = starts_with("E"))
3361
+
5×6 DataFrame
3362
+
Row │ A E B C D F
3363
+
│ Int64 Int64 Int64 String Char String
3364
+
─────┼───────────────────────────────────────────
3365
+
1 │ 1 1 6 A A A
3366
+
2 │ 2 2 7 b B b
3367
+
3 │ 3 3 8 C A C
3368
+
4 │ 4 4 9 D B D
3369
+
5 │ 5 5 10 E C E
3370
+
3371
+
julia> @relocate(df, B:C) # bring columns to the front
0 commit comments