Sunday 29 March 2020

TableSaw: Selection.with : Select specific rows

‘Selection.with’ method is used to select the row at given index.

Example
IntColumn filteredElements = intColumn.where(Selection.with(0, 2, 4, 6));

App.java
package com.sample.app;

import tech.tablesaw.api.IntColumn;
import tech.tablesaw.selection.Selection;

public class App {

 public static void main(String args[]) {
  int[] numbers = { 2, 4, 103, 24, 53, 23, 12, 11, 56, 6 };

  IntColumn intColumn = IntColumn.create("My Numbers", numbers);

  IntColumn filteredElements = intColumn.where(Selection.with(0, 2, 4, 6));

  System.out.println(intColumn.print() + "\n");

  filteredElements.setName("Filtered Elements");
  System.out.println(filteredElements.print());
 }
}

Output
Column: My Numbers
2
4
103
24
53
23
12
11
56
6


Column: Filtered Elements
2
103
53
12


Previous                                                    Next                                                    Home

No comments:

Post a Comment