Parent

Rserve::RFactor

Attributes

ids[R]
levels[R]
index_base[R]

Public Class Methods

new(i,v,copy,index_base) click to toggle source
# File lib/rserve/rfactor.rb, line 6
def initialize(i,v,copy,index_base)
  i=[] if i.nil?
  v=[] if v.nil?
  if (copy)
    @ids=i.dup
    @levels=v.dup
  else
    @ids=i
    @levels=v
  end
  @index_base=index_base
end

Public Instance Methods

[](i) click to toggle source

returns the level of a given case

  • @param i case number

  • @return name. may throw exception if out of range

# File lib/rserve/rfactor.rb, line 21
def [](i)
  li = @ids[i]-index_base
  return (li<0 or li>levels.length) ? nil : levels[li]
end
Also aliased as: at
as_integers() click to toggle source
# File lib/rserve/rfactor.rb, line 48
def as_integers
  @ids
end
as_strings() click to toggle source
# File lib/rserve/rfactor.rb, line 51
def as_strings
  @ids.map {|v| v==REXP::Integer::NA ? nil : @levels[v-index_base]}
end
at(i) click to toggle source
Alias for: []
contains?(li) click to toggle source
# File lib/rserve/rfactor.rb, line 25
def contains?(li)
  li=level_index(li) if li.is_a? String
  @ids.any? {|v| v==li}
end
count(li) click to toggle source
# File lib/rserve/rfactor.rb, line 38
def count(li)
  li=level_index(li) if li.is_a? String
  @ids.inject(0) {|ac,v| ac+ ((v==li) ? 1 : 0 ) }
end
counts_hash() click to toggle source

return a hash with levels as keys and counts as values

# File lib/rserve/rfactor.rb, line 43
def counts_hash
  h=@levels.inject({}) {|ac,v| ac[v]=0;ac}
  @ids.each {|v| h[@levels[v-index_base]]+=1}
  h
end
index_at(i) click to toggle source
# File lib/rserve/rfactor.rb, line 54
def index_at(i)
  @ids[i]
end
level_index(name) click to toggle source

return the index of a given level name or -1 if it doesn’t exist

# File lib/rserve/rfactor.rb, line 31
def level_index(name)
  return nil if name.nil?
  levels.length.times {|i|
    return i+index_base if !levels[i].nil? and levels[i]==name
  }
  return nil
end
size() click to toggle source
# File lib/rserve/rfactor.rb, line 57
def size
  @ids.length
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.