HarlanH/DataFrames.jl — pull request #99 by tshort (2012-12-08 13:42:26+00:00)
Title: [RFC] @transform and @DataFrame

I wrote versions of `@transform` and `@DataFrame`. See also issue #95. The advantages are:

* Nicer constructor syntax. `@DataFrame(a => 1, b => [1:5])` You can use `=>` or `:=` but not `=` with this format.
* No need to use $() to splice in outside variables.

The disadvantages of including them are:

* Expressions are nicer for passing around, and we should generally try to encourage that form of entry.
* Since macros can't really do multiple dispatch, it's more difficult to make them work generally. `@transform` works for DataFrame, Dict, and NamedArray types, but it does not work for GroupedDataFrames.

These are my main hesitations for going ahead and committing, so I'd like opinions. Here are examples:

```jul
julia> load("DataFrames"); using DataFrames
Warning: redefinition of constant NARule ignored.

julia> d = @DataFrame(a => pi, b => [1:5])
DataFrame (5,2)
a b
[1,] 3.14159 1
[2,] 3.14159 2
[3,] 3.14159 3
[4,] 3.14159 4
[5,] 3.14159 5

julia> @transform(d, c => a .* b)
DataFrame (5,3)
a b c
[1,] 3.14159 1 3.14159
[2,] 3.14159 2 6.28319
[3,] 3.14159 3 9.42478
[4,] 3.14159 4 12.5664
[5,] 3.14159 5 15.708

julia> @transform(d, a => mean(b))
DataFrame (5,3)
a b c
[1,] 3.0 1 3.14159
[2,] 3.0 2 6.28319
[3,] 3.0 3 9.42478
[4,] 3.0 4 12.5664
[5,] 3.0 5 15.708

julia> @transform d a=mean(b) c=99*c
DataFrame (5,3)
a b c
[1,] 3.0 1 311.018
[2,] 3.0 2 622.035
[3,] 3.0 3 933.053
[4,] 3.0 4 1244.07
[5,] 3.0 5 1555.09

julia> z = 33
33

julia> @transform d c=c/z
DataFrame (5,3)
a b c
[1,] 3.0 1 9.42478
[2,] 3.0 2 18.8496
[3,] 3.0 3 28.2743
[4,] 3.0 4 37.6991
[5,] 3.0 5 47.1239

```