How do you change multiple column names in a Julia (version 0.3) DataFrame?

julia

Solution

You might find the `names!` function more concise:

julia> using DataFrames

julia> df = DataFrame(x1 = 1:2, x2 = 2:3, x3 = 3:4)
2x3 DataFrame
|-------|----|----|----|
| Row # | x1 | x2 | x3 |
| 1     | 1  | 2  | 3  |
| 2     | 2  | 3  | 4  |

julia> names!(df, [symbol("col$i") for i in 1:3])
Index([:col2=>2,:col1=>1,:col3=>3],[:col1,:col2,:col3])

julia> df
2x3 DataFrame
|-------|------|------|------|
| Row # | col1 | col2 | col3 |
| 1     | 1    | 2    | 3    |
| 2     | 2    | 3    | 4    |

Problem

For example say you create a Julia DataFrame like so with 20 columns: ``` y=convert(DataFrame, randn(10,20)) ``` How do you convert the column names `(:x1 ... :x20)` to something else, like `(:col1, ..., :col20)` for example, all at once?

Original source