-
Notifications
You must be signed in to change notification settings - Fork 57
Another attempt at an astable flag #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 26 commits
a8701c8
9b997a6
d639560
b77e8ca
3cdf0d5
b878fbb
2344a2e
6557def
6002def
08a1c4b
581b2cf
7cc8947
0eca67d
a4ab9a6
ab9bae4
495f08a
01cb5e7
01fb3b7
915191c
a331fc2
2ce4d9e
57b4051
da7674d
285e3ac
713eaf0
4e01c4a
09c692a
ae26da8
a7fd1a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ In addition, DataFramesMeta provides | |
| convenient syntax. | ||
| * `@byrow` for applying functions to each row of a data frame (only supported inside other macros). | ||
| * `@passmissing` for propagating missing values inside row-wise DataFramesMeta.jl transformations. | ||
| * `@astable` to create multiple columns within a single transformation. | ||
| * `@chain`, from [Chain.jl](https://github.com/jkrumbiegel/Chain.jl) for piping the above macros together, similar to [magrittr](https://cran.r-project.org/web/packages/magrittr/vignettes/magrittr.html)'s | ||
| `%>%` in R. | ||
|
|
||
|
|
@@ -396,11 +397,38 @@ julia> @rtransform df @passmissing x = parse(Int, :x_str) | |
| 3 │ missing missing | ||
| ``` | ||
|
|
||
| ## Creating multiple columns at once with `@astable` | ||
|
|
||
| Often new variables may depend on the same intermediate calculations. `@astable` makes it easy to create multiple | ||
| new variables in the same operation, yet have them share | ||
| information. | ||
|
|
||
| In a single block, all assignments of the form `:y = f(:x)` | ||
| or `$y = f(:x)` at the top-level generate new columns. In the 2nd example, `y` | ||
| must be a string or `Symbol`. | ||
|
|
||
| ``` | ||
| julia> df = DataFrame(a = [1, 2, 3], b = [400, 500, 600]); | ||
|
|
||
| julia> @transform df @astable begin | ||
| ex = extrema(:b) | ||
| :b_first = :b .- first(ex) | ||
| :b_last = :b .- last(ex) | ||
| end | ||
| 3×4 DataFrame | ||
| Row │ a b b_first b_last | ||
| │ Int64 Int64 Int64 Int64 | ||
| ─────┼─────────────────────────────── | ||
| 1 │ 1 400 0 -200 | ||
| 2 │ 2 500 100 -100 | ||
| 3 │ 3 600 200 0 | ||
| ``` | ||
|
|
||
|
|
||
| ## [Working with column names programmatically with `$`](@id dollar) | ||
|
|
||
| DataFramesMeta provides the special syntax `$` for referring to | ||
| columns in a data frame via a `Symbol`, string, or column position as either | ||
| a literal or a variable. | ||
| columns in a data frame via a `Symbol`, string, or column position as either a literal or a variable. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we are at it given our recent discussion on Discourse, I think it is essential to mention when the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will do this as another PR. In summary, you can't use other macros which use
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be clear why I stress it so much. With DataFrames.jl my answer to users is: if you learn Julia Base then you will know exactly how DataFrames.jl works. With DataFramesMeta.jl unfortunately this is not the case as it is a DSL so we need to be very precise how things work in documentation. |
||
|
|
||
| ```julia | ||
| df = DataFrame(A = 1:3, B = [2, 1, 2]) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.