public SEXP buildFactorsMatrix() {
if(terms.size() == 0) {
return new IntArrayVector();
} else {
List<SEXP> variables = uniqueVariables();
IntMatrixBuilder matrix = new IntMatrixBuilder(variables.size(), terms.size());
matrix.setRowNames(Collections2.transform(variables, Functions.toStringFunction()));
matrix.setColNames(buildTermLabels());
for(int row = 0; row != variables.size(); ++row) {
for(int col = 0; col != terms.size(); ++col) {
if(terms.get(col).getExpressions().contains(
variables.get(row))) {
// TODO(alex): I don't know when this should be 1 or 2??
matrix.set(row, col, 1);
} else {
matrix.set(row, col, 0);
}
}
}
return matrix.build();
}
}