Class: Array

Inherits:
Object
  • Object
show all
Defined in:
lib/statsample.rb,
lib/statsample/vector.rb,
lib/statsample/dataset.rb

Instance Method Summary collapse

Instance Method Details

#prefix(s) ⇒ Object

:nodoc:



11
12
13
# File 'lib/statsample/dataset.rb', line 11

def prefix(s) # :nodoc:
  self.collect{|c| s+c.to_s }
end

#recode_repeatedObject

Recode repeated values on an array, adding the number of repetition at the end Example:

a=%w{a b c c d d d e}
a.recode_repeated
=> ["a","b","c_1","c_2","d_1","d_2","d_3","e"]


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/statsample.rb', line 49

def recode_repeated
  if self.size!=self.uniq.size
    # Find repeated
    repeated=self.inject({}) {|a,v|
    (a[v].nil? ? a[v]=1 : a[v]+=1); a }.find_all{|k,v| v>1}.collect{|k,v| k}
    ns=repeated.inject({}) {|a,v| a[v]=0;a}
    self.collect do |f|
      if repeated.include? f
        ns[f]+=1
        sprintf("%s_%d",f,ns[f])
      else
        f
      end
    end
  else
    self
  end
end

#suffix(s) ⇒ Object

:nodoc:



14
15
16
# File 'lib/statsample/dataset.rb', line 14

def suffix(s) # :nodoc:
  self.collect{|c| c.to_s+s }
end

#to_scale(*args) ⇒ Object

Creates a new Statsample::Vector object of type :scale



9
10
11
# File 'lib/statsample/vector.rb', line 9

def to_scale(*args)
    Statsample::Vector.new(self,:scale,*args)
end

#to_vector(*args) ⇒ Object

Creates a new Statsample::Vector object Argument should be equal to Vector.new



5
6
7
# File 'lib/statsample/vector.rb', line 5

def to_vector(*args)
  Statsample::Vector.new(self,*args)
end