Revision 2704
tmp/org.txm.statsengine.r.core/src/org/txm/statsengine/r/core/data/MatrixImpl.java (revision 2704)  

323  323 
public void filter(int nlines, int fmin, int fmax) throws RWorkspaceException, REXPMismatchException { 
324  324 
RWorkspace rw = RWorkspace.getRWorkspaceInstance(); 
325  325 

326 
if (nlines < 1) nlines = 1; 

327 
if (fmax < fmin) fmax = fmin; 

328 


326  329 
// first sort rows 
327  330 
rw.eval("freqs < rowSums(" + symbol + ")"); //$NONNLS1$ //$NONNLS2$ 
328  331 
int[] freqs = rw.eval("freqs").asIntegers(); //$NONNLS1$ 
329  332 
rw.eval("order < sort(freqs, decreasing= TRUE, index.return= TRUE)"); //$NONNLS1$ 
330  333 
// rw.eval("print(order)"); 
331  334 

332 
// get table sort indexes 

335 
// get table sort indexes : from max to min


333  336 
int[] order = rw.eval("order$ix").asIntegers(); //$NONNLS1$ 
334  337 

335 
// sort the table 

338 
// sort the table to cut later


336  339 
rw.eval(symbol + "< " + symbol + "[order$ix, ];"); //$NONNLS1$ //$NONNLS2$ 
337  340 

338  341 
// find first fmin line 
339 
int ifmin = 999999999;


340 
int ifmax = 0;


341 
for (int i = 0; i < order.length; i++) { 

342 
int ifmin = order.length;


343 
int ifmax = 1;


344 
for (int i = 0; i < order.length; i++) { // iterate from max to min freqs


342  345 
// System.out.print("\t"+i+" freqs["+order[i]+"]"+freqs[order[i]1]); 
343  346 
if (freqs[order[i]  1] < fmin) { // minus 1 because of R indexes 
344  347 
ifmin = i; // the ith line 
...  ...  
347  350 
} 
348  351 
// ifmin = Math.min(order.length  1, ifmin); 
349  352 

350 
for (int i = order.length  1; i >= 0; i) {


353 
for (int i = ifmin  1; i >= 0; i) { // iterate from min to max freqs


351  354 
// System.out.print("\t"+i+" freqs["+order[i]+"]"+freqs[order[i]1]); 
352  355 
// System.out.println("i=" + i + " o=" + order[i] + " f=" + freqs[order[i]  1]); 
353  356 
if (freqs[order[i]  1] > fmax) { // minus 1 because of R indexes 
...  ...  
356  359 
} 
357  360 
} 
358  361 

362 
ifmin = Math.max(1, Math.min(nlines, ifmin)); 

363 
ifmax = Math.max(1, ifmax); 

359  364 
// cut 
360 
cut(Math.max(1, ifmax), Math.min(nlines, ifmin)); 

365 


366 
cut(ifmax, ifmin); // ifmax is always < to fmin, because of the decreasing loop index 

367 


361  368 
} 
362  369 

363  370 
/** 
364  371 
* Cut. 
365  372 
* 
366 
* @param nRowToCut the nlines 

373 
* @param before lines before 'before' are removed 

374 
* @param after lines after 'after' are removed 

367  375 
* @throws StatException 
368  376 
*/ 
369  377 
public void cut(int before, int after) { 
Also available in: Unified diff