org.rosuda.REngine
Class RFactor

java.lang.Object
  extended by org.rosuda.REngine.RFactor

public class RFactor
extends java.lang.Object

representation of a factor variable. In R there is no actual object type called "factor", instead it is coded as an int vector with a list attribute. The parser code of REXP converts such constructs directly into the RFactor objects and defines an own XT_FACTOR type

Version:
$Id: RFactor.java 2841 2008-02-27 18:47:46Z urbanek $

Constructor Summary
RFactor()
          create a new, empty factor var
RFactor(int[] i, java.lang.String[] v)
          same as RFactor(i,v, true, 1)
RFactor(int[] i, java.lang.String[] v, boolean copy, int index_base)
          create a new factor variable, based on the supplied arrays.
RFactor(java.lang.String[] c)
          same as RFactor(c, 1)
RFactor(java.lang.String[] c, int index_base)
          create a new factor variable by factorizing a given string array.
 
Method Summary
 int[] asIntegers()
          return the contents as integer indices (with the index base of this factor)
 int[] asIntegers(int desired_index_base)
          return the contents as integer indices with a given index base
 java.lang.String[] asStrings()
          return the factor as an array of strings
 java.lang.String at(int i)
          returns the level of a given case
 boolean contains(int li)
          returns true if the data contain the given level index
 boolean contains(java.lang.String name)
          return true if the factor contains the given level (it is NOT the same as levelIndex==-1!)
 int count(int levelIndex)
          count the number of occurences of a given level index
 int count(java.lang.String name)
          count the number of occurences of a given level name
 int[] counts()
          return an array with level counts.
 int indexAt(int i)
          return the level index for a given case
 int indexBase()
          return the base of the levels index
 java.lang.String levelAtIndex(int li)
          return the level name for a given level index
 int levelIndex(java.lang.String name)
          return the index of a given level name or -1 if it doesn't exist
 java.lang.String[] levels()
          return the list of levels (0-based, use indexBase() correction if you want to access it by level index)
 int size()
          returns the number of cases
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RFactor

public RFactor()
create a new, empty factor var


RFactor

public RFactor(int[] i,
               java.lang.String[] v,
               boolean copy,
               int index_base)
create a new factor variable, based on the supplied arrays.

Parameters:
i - array of IDs (inde_base..v.length+index_base-1)
v - values - cotegory names
copy - copy above vaules or just retain them
index_base - index of the first level element (1 for R factors, cannot be negtive)

RFactor

public RFactor(java.lang.String[] c,
               int index_base)
create a new factor variable by factorizing a given string array. The levels will be created in the orer of appearance.

Parameters:
c - contents
index_base - base of the level index

RFactor

public RFactor(java.lang.String[] c)
same as RFactor(c, 1)


RFactor

public RFactor(int[] i,
               java.lang.String[] v)
same as RFactor(i,v, true, 1)

Method Detail

at

public java.lang.String at(int i)
returns the level of a given case

Parameters:
i - case number
Returns:
name. may throw exception if out of range

contains

public boolean contains(int li)
returns true if the data contain the given level index


contains

public boolean contains(java.lang.String name)
return true if the factor contains the given level (it is NOT the same as levelIndex==-1!)


count

public int count(int levelIndex)
count the number of occurences of a given level index


count

public int count(java.lang.String name)
count the number of occurences of a given level name


counts

public int[] counts()
return an array with level counts.


levelIndex

public int levelIndex(java.lang.String name)
return the index of a given level name or -1 if it doesn't exist


levels

public java.lang.String[] levels()
return the list of levels (0-based, use indexBase() correction if you want to access it by level index)


asIntegers

public int[] asIntegers()
return the contents as integer indices (with the index base of this factor)


asIntegers

public int[] asIntegers(int desired_index_base)
return the contents as integer indices with a given index base


levelAtIndex

public java.lang.String levelAtIndex(int li)
return the level name for a given level index


indexAt

public int indexAt(int i)
return the level index for a given case


asStrings

public java.lang.String[] asStrings()
return the factor as an array of strings


indexBase

public int indexBase()
return the base of the levels index


size

public int size()
returns the number of cases


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object