HarlanH/julia — pull request #2 by tshort (2012-06-23 12:08:27+00:00)
Title: Add with, within!, and transform!

This is tweaked a little from what I posted on the mailing list. Here is some example output:

```jl
julia> c1 = DataVec([5:8])
[5,6,7,8]

julia> c2 = DataVec([5:8] + 3)
[8,9,10,11]

julia> dv = DataVec([5:8] - 3)
[2,3,4,5]

julia> df = DataFrame({c1, c2}, ["C1", "C2"])
C1 C2
[1,] 5 8
[2,] 6 9
[3,] 7 10
[4,] 8 11

julia> a = with(df, :( C1 + C2 - 1 ))
[12,14,16,18]

julia> transform!(df, "Cnew", :( C1 + C2 - 1 ))
[12,14,16,18]

julia> df
C1 C2 Cnew
[1,] 5 8 12
[2,] 6 9 14
[3,] 7 10 16
[4,] 8 11 18

julia> within!(df, :( C1 + C2 - 1 ))
C1 C2 Cnew
[1,] 5 8 12
[2,] 6 9 14
[3,] 7 10 16
[4,] 8 11 18

julia> within!(df, quote
a = C1 + C2 - 1
b = 2 + C1
end)
C1 C2 Cnew a b
[1,] 5 8 12 12 7
[2,] 6 9 14 14 8
[3,] 7 10 16 16 9
[4,] 8 11 18 18 10

julia> df
C1 C2 Cnew a b
[1,] 5 8 12 12 7
[2,] 6 9 14 14 8
[3,] 7 10 16 16 9
[4,] 8 11 18 18 10

julia>

julia> df = DataFrame({c1, c2}, ["C1", "C2"])
C1 C2
[1,] 5 8
[2,] 6 9
[3,] 7 10
[4,] 8 11

julia> df | quote
a = C1 + C2 - 1
b = 2 + C1
end
C1 C2 a b
[1,] 5 8 12 7
[2,] 6 9 14 8
[3,] 7 10 16 9
[4,] 8 11 18 10

julia> df
C1 C2 a b
[1,] 5 8 12 7
[2,] 6 9 14 8
[3,] 7 10 16 9
[4,] 8 11 18 10

julia> df | with(:( C2 .* C1 ))
[40,54,70,88]

julia> df | with(:( C2 .* _DF[1] )) # _DF is the whole DataFrame
[40,54,70,88]

```