JuliaStats/DataFrames.jl — pull request #474 by kmsquire (2014-01-13 23:56:31+00:00)
Title: Implementation of a DataFrame row as a parameterized SubDataFrame

As suggested by @StefanKarpinski [here](https://github.com/JuliaStats/DataFrames.jl/issues/375#issuecomment-26205839), this PR parameterizes `SubDataFrames` by the type of `rows`.

At this point, I've only implemented `Int` (for individual rows) and `Vector{Int}` (for everything else). Parameterizing by `Range1{Int}`, as Stefan suggested, would also be a good addition.

This makes indexing within rows more natural, as requested in #375--i.e., the elements of each row can be accessed either by name (`Dict`-like), or numerical index (`Array`-like).

Some examples:

```julia
julia> df = DataFrame(A = 1:4, B = ["M", "F", "F", "M"])
4x2 DataFrame
|-------|---|---|
| Row # | A | B |
| 1 | 1 | M |
| 2 | 2 | F |
| 3 | 3 | F |
| 4 | 4 | M |

julia> for row in EachRow(df)
println(row)
end
1x2 SubDataFrame{Int64}
|-------|---|---|
| Row # | A | B |
| 1 | 1 | M |

1x2 SubDataFrame{Int64}
|-------|---|---|
| Row # | A | B |
| 1 | 2 | F |

1x2 SubDataFrame{Int64}
|-------|---|---|
| Row # | A | B |
| 1 | 3 | F |

1x2 SubDataFrame{Int64}
|-------|---|---|
| Row # | A | B |
| 1 | 4 | M |

julia> for row in EachRow(df)
println(row["A"], " ", row[2])
end
1 M
2 F
3 F
4 M

julia> row = sub(df, 2)
1x2 SubDataFrame{Int64}
|-------|---|---|
| Row # | A | B |
| 1 | 2 | F |

julia> row["A"] = 200
200

julia> df
4x2 DataFrame
|-------|-----|---|
| Row # | A | B |
| 1 | 1 | M |
| 2 | 200 | F |
| 3 | 3 | F |
| 4 | 4 | M |

```

Note that this is a **BREAKING** change

Before:
```julia
julia> row = EachRow(df)[1]
1x2 DataFrame
|-------|---|---|
| Row # | A | B |
| 1 | 1 | M |

julia> row[1]
1-element DataArray{Int64,1}:
1

julia> typeof(row)
DataFrame (constructor with 22 methods)
```

After:
```julia
julia> row = EachRow(df)[1]
1x2 SubDataFrame{Int64}
|-------|---|---|
| Row # | A | B |
| 1 | 1 | M |

julia> row[1]
1

julia> typeof(row)
SubDataFrame{Int64} (constructor with 1 method)
```