Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,43 @@ or via the `Pkg` REPL mode (enter by typing `]` at the REPL console)
] add DataFramesMeta
```

# Usage

Instead of using DataFrames.jl [manipulation functions](https://dataframes.juliadata.org/stable/man/basics/#Manipulation-Functions) directly,
which use operation pairs to define data frame manipulations,
DataFramesMeta.jl offers macro alternatives to each manipulation function,
which convert a more readable syntax into the appropriate DataFrames.jl function calls.
This syntax simplification is demonstrated with two simple examples below.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add something how its similar to R's dplyr?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't mean anything to me, but you can include a statement like that if you wish.


Define a data frame.

```julia
# Importing DataFramesMeta also implicitly imports DataFrames
using DataFramesMeta
df = DataFrame(a = [1, 2], b = [3, 4])
```

Add columns `a` and `b` together and store the result in a new column `c`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Add columns `a` and `b` together and store the result in a new column `c`.
Add columns `:a` and `:b` together and store the result in a new column `:c`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The column's name is a regardless of the type used to store the name. I think "a" would have similar meaning if you prefer that to `a`. But I won't fight you further if you really want to use `:a`.


```julia
# With DataFrames
transform(df, [:a, :b] => ((x, y) -> x + y) => :c)

# With DataFramesMeta
@transform(df, :c = :a + :b)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@transform(df, :c = :a + :b)
@transform df :c = :a + :b

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

```

Show only the data frame rows where column `a` is equal to `2`.
(DataFramesMeta.jl offers rowwise 'r' versions of each manipulation macro as well for convenience.)

```julia
# With DataFrames
subset(df, :a => ByRow(==(2)))

# With DataFramesMeta
@rsubset(df, :a == 2)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove parentheses? So it looks cleaner.

Suggested change
@rsubset(df, :a == 2)
@rsubset df :a == 2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't personally like the whitespace-dependent syntax, but your call. I am using the same examples from https://juliadata.org/DataFramesMeta.jl/dev/#Introduction which already have parentheses, so I'd change both or neither.

```

# Documentation

* [Stable](https://JuliaData.github.io/DataFramesMeta.jl/stable)
Expand All @@ -37,3 +74,7 @@ Pull requests are welcome. Pull requests should include updated tests. If
functionality is changed, docstrings should be added or updated. Generally,
follow the guidelines in
[DataFrames](https://github.com/JuliaData/DataFrames.jl/blob/master/CONTRIBUTING.md).

# Alternatives

Other high-level data frame manipulation packages are described briefly [here](https://dataframes.juliadata.org/stable/man/querying_frameworks/).
Loading