def reindex! idx
      idx = Daru::Index.new idx unless idx.is_a? Daru::Index
      raise ArgumentError, 'Invalid index specified' unless
        idx.to_a.sort == index.to_a.sort

      old_categories = categories
      data = idx.map { |i| self[i] }
      initialize_core_attributes data
      self.categories = old_categories
      self.index = idx
      self
    end
def reindex! idx
      idx = Daru::Index.new idx unless idx.is_a? Daru::Index
      raise ArgumentError, 'Invalid index specified' unless
        idx.to_a.sort == index.to_a.sort

      old_categories = categories
      data = idx.map { |i| self[i] }
      initialize_core_attributes data
      self.categories = old_categories
      self.index = idx
      self
    end
Sets new index for vector. Preserves index->value correspondence.
 @note Unlike #reorder! which takes positions as input it takes
   index as an input to reorder the vector
 @param [Daru::Index, Daru::MultiIndex, Array] idx new index to order with
 @return [Daru::Vector] vector reindexed with new index
 @example
   dv = Daru::Vector.new [3, 2, 1], index: ['c', 'b', 'a'], type: :category
   dv.reindex! ['a', 'b', 'c']
   # => #<Daru::Vector(3)>
   #   a   1
   #   b   2
   #   c   3