Method: Daru::Vector#only_valid
- Defined in:
- lib/daru/vector.rb
#only_valid(as_a = :vector, duplicate = true) ⇒ Object
Creates a new vector consisting only of non-nil data
Arguments
as an Array. Otherwise will return a Daru::Vector.
vector, setting this to false will return the same vector. Otherwise, a duplicate will be returned irrespective of presence of missing data.
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 |
# File 'lib/daru/vector.rb', line 1060 def only_valid as_a=:vector, duplicate=true return dup if !has_missing_data? && as_a == :vector && duplicate return self if !has_missing_data? && as_a == :vector && !duplicate return to_a if !has_missing_data? && as_a != :vector new_index = @index.to_a - missing_positions new_vector = new_index.map do |idx| self[idx] end return new_vector if as_a != :vector Daru::Vector.new new_vector, index: new_index, name: @name, metadata: .dup, dtype: dtype end |