HarlanH/JuliaData — pull request #38 by tshort (2012-07-20 01:43:36+00:00)
Title: Grouped data columns, implementing issue #36.

This turned out to be pretty easy given that column names are stored in a Dict. We can just add groupings in with those. Some things of note:

* This isn't a hierarchical index like pandas. Groupings can overlap.

* Overlapping indexes will repeat columns in the output.

Examples:

```julia
d = DataFrame(quote
y1 = randn(10)
y2 = randn(10)
x1 = randn(10)
x2 = randn(10)
x3 = randn(10)
end)

add_group(d, "responses", ["y1", "y2"])
add_group(d, "odd_predictors", ["x1", "x3"])
add_group(d, "predictors", ["odd_predictors", "x2"])

# Usage:

julia> d[1:3,"responses"]
DataFrame (3,2)
y1 y2
[1,] -0.000745666 0.583151
[2,] 0.246578 -0.411998
[3,] -0.506249 -1.63488

julia> d[1:3,"predictors"]
DataFrame (3,3)
x1 x3 x2
[1,] 0.389423 1.31454 -0.476905
[2,] 0.704261 -0.80892 -0.728721
[3,] -0.684409 -0.371066 -0.49958

julia> d[1:3,["predictors", "y1"]]
DataFrame (3,4)
x1 x3 x2 y1
[1,] 0.389423 1.31454 -0.476905 -0.000745666
[2,] 0.704261 -0.80892 -0.728721 0.246578
[3,] -0.684409 -0.371066 -0.49958 -0.506249

julia> d[1:3,["odd_predictors", "x1"]]
DataFrame (3,3)
x1 x3 x1
[1,] 0.389423 1.31454 0.389423
[2,] 0.704261 -0.80892 0.704261
[3,] -0.684409 -0.371066 -0.684409
```