Subscribe Bookmark RSS Feed

select matching cells

zhouye0

Community Trekker

Joined:

Mar 2, 2016

by the end of the thing, my expected output should be 3 subset tables.

So I want to do this:

1) Go to a specific column,

2) Go to the first row of the column, and select matching cells, and group them to a subset table

dt << Select Matching Cells;

3) Then I want to skip the rest of the cell that I have matched, and move on to the next unique cell, and select the matching cells, and group them to a new subset table.. How do I do that? My table looks something like this

FruitQty
Banana2
Apple5
Apple7
Banana7
Banana1
Banana5
Banana5
Apple8
Pear5
Pear4
1 ACCEPTED SOLUTION

Accepted Solutions
Solution

There are many ways to do this in JSL, but here's one:

NamesDefaultToHere(1);

// Sample Data

dt = NewTable("Sample Data",

NewColumn("My Col", Numeric, Nominal, Formula(RandomInteger(4))),

AddRows(50)

);

// Get unique values

uVals = AssociativeArray(:My Col << getValues) << getKeys;

// Make Subset Tables

for(g = 1, g <= NItems(uVals), g++,

r2get = dt << getRowsWhere(:My Col == uVals[g]);

dt2 = dt << subset(Rows(r2get));

dt2 << setName("Subset of "||(dt << getName)||" with My Col = "||Char(uVals[g]));

);


1 REPLY
Solution

There are many ways to do this in JSL, but here's one:

NamesDefaultToHere(1);

// Sample Data

dt = NewTable("Sample Data",

NewColumn("My Col", Numeric, Nominal, Formula(RandomInteger(4))),

AddRows(50)

);

// Get unique values

uVals = AssociativeArray(:My Col << getValues) << getKeys;

// Make Subset Tables

for(g = 1, g <= NItems(uVals), g++,

r2get = dt << getRowsWhere(:My Col == uVals[g]);

dt2 = dt << subset(Rows(r2get));

dt2 << setName("Subset of "||(dt << getName)||" with My Col = "||Char(uVals[g]));

);