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
| Fruit | Qty |
|---|---|
| Banana | 2 |
| Apple | 5 |
| Apple | 7 |
| Banana | 7 |
| Banana | 1 |
| Banana | 5 |
| Banana | 5 |
| Apple | 8 |
| Pear | 5 |
| Pear | 4 |
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]));
);
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]));
);