Method: Statsample::Codification._recode_dataset

Defined in:
lib/statsample/codification.rb

._recode_dataset(dataset, h, sep = Statsample::SPLIT_TOKEN, split = false) ⇒ Object


145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/statsample/codification.rb', line 145

def _recode_dataset(dataset, h , sep=Statsample::SPLIT_TOKEN, split=false)
  v_names||=h.keys
  v_names.each do |v_name|
    raise Exception, "Vector #{v_name} doesn't exists on Dataset" if !dataset.vectors.include? v_name
    recoded = Daru::Vector.new(
      recode_vector(dataset[v_name], h[v_name],sep).collect do |c|
        if c.nil?
          nil
        else
          c.join(sep)
        end
      end
    )
    if split
      recoded.split_by_separator(sep).each {|k,v|
        dataset[(v_name.to_s + "_" + k).to_sym] = v
      }
    else
      dataset[(v_name.to_s + "_recoded").to_sym] = recoded
    end
  end
end