The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here

Traverse trough dataset in reverse order

wesselwessel Member Posts: 537 Maven
edited November 2018 in Help
Dear All, I posted the script below a long time ago, it creates some attributes with values depending on previous data rows.
Is it possible to do the loop: for (Example e : exampleSet) {  } in reverse order somehow?





import com.rapidminer.operator.Operator;
import com.rapidminer.Process;
import com.rapidminer.MacroHandler;
import com.rapidminer.tools.Ontology

ExampleSet exampleSet = operator.getInput(ExampleSet.class);

Attribute sum = AttributeFactory.createAttribute("sum", Ontology.REAL);
exampleSet.getExampleTable().addAttribute(sum);
exampleSet.getAttributes().addRegular(sum);

Attribute avg = AttributeFactory
.createAttribute("avg", Ontology.REAL);
exampleSet.getExampleTable().addAttribute(avg);
exampleSet.getAttributes().addRegular(avg);

last = 0;
n = 0;

for (Example e : exampleSet) { 
      e["sum"] = e["abs"] + last; // iterate over an attribute using the name of the attribute
      last = e["sum"];
      n++;
      e["avg"] = last / n;
}


return exampleSet
Sign In or Register to comment.