SciRuby / daru

Data Analysis in RUby
BSD 2-Clause "Simplified" License
1.04k stars 139 forks source link

Reorder vectors in a dataframe #245

Closed lokeshh closed 8 years ago

lokeshh commented 8 years ago

I want to reorder vectors in a dataframe. For example:

>> df = Daru::DataFrame.new(
?> a: [1, 2, 3],
?> b: [4, 5, 6]
>> )
=> #<Daru::DataFrame(3x2)>
       a   b
   0   1   4
   1   2   5
   2   3   6

>> df.order = [:b, :a]
>> df
=> #<Daru::DataFrame(3x2)>
       b   a
   0   4   1
   1   5   2
   2   6   3
v0dro commented 8 years ago

Works. My only sugesstion is that the method name should be something descriptive like DataFrame#reorder_vectors.

lokeshh commented 8 years ago

Is order= fine?

v0dro commented 8 years ago

Alright. When order= is used, the new order passed should contain all the vector names that were present in the previous order. That way order= will be different from vectors=, which allows you to change the names of the vectors.