Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 339
John St. John Avatar asked Feb 04 '14 17:02

John St. John


People also ask

How do I select specific columns in Julia?

We can use: Symbol : select(df, :col) String : select(df, "col") Integer : select(df, 1)

How do I change multiple column names in a DataFrame in R?

rename() is the method available in the dplyr library which is used to change the multiple columns (column names) by name in the dataframe. The operator – %>% is used to load the renamed column names to the dataframe. At a time it will change single or multiple column names.

How do I change column names in a DataFrame in R?

Method 1: using colnames() method colnames() method in R is used to rename and replace the column names of the data frame in R. The columns of the data frame can be renamed by specifying the new column names as a vector. The new name replaces the corresponding old name of the column in the data frame.


1 Answers

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    | 
like image 149
John Myles White Avatar answered Oct 05 '22 08:10

John Myles White