14 things you can do with lists.
Create An Empty List
1 2 3 4 5 |
// method 1 lst = List(); // method 2 lst = {}; |
Initialise a List
1 2 3 |
lst1 = {1,2,3}; lst2 = {"A","B","C","D"}; lst3 = {"David",20,"John",25}; |
Create a List from a Column
1 2 3 4 5 6 7 |
dt = Open("$SAMPLE_DATA\Big Class.jmp"); lst = Column(dt,"Name") << Get Values; // {"KATIE","LOUISE",...} Close(dt,NoSave); dt = Open("$SAMPLE_DATA\Big Class.jmp"); mat = Column(dt,"Height") << Get Values; // [59,61,44,...] - matrix! lst = As List(mat); // {59,61,44,...} |
Create a Column from a List
1 2 3 4 |
lst = {1,2,3,4,5}; New Table("my table", New Column("my column", Set Values(lst) ) ); |
Copy a List
1 2 |
lst1 = {1,2,3}; lst2 = lst1; // {1,2,3} |
Concatenate Lists
1 2 3 |
lst1 = {1,2,3}; lst2 = {4,5,6}; lst3 = lst1 || lst2; // {1,2,3,4,5,6} |
Count the Items in a List
1 2 |
lst = {"A","B","C","D"}; n = NItems(lst); // n = 4 |
Sort a List
1 2 3 4 5 6 7 8 9 |
lst1 = {1,4,2,3}; lst2 = SortList(lst); // {1,2,3,4} lst3 = {"D","A","V","E"}; SortListInto(lst3); // lst3 -> {"A","D","E","V"} lst4 = {"D","A","V","E"}; ri = RankIndex(lst4); // ri = [2,1,4,3] lst5 = lst4[ri] // lst5 = {"A", "D", "E", "V"} |
Locate an Item in a List
1 2 |
lst = {1,5,2,3,4,2}; pos = Loc(lst,2); // pos = [3,6] |
Count the Number of Occurrences within a List
1 2 3 |
lst = {1,5,2,3,4,2}; pos = Loc(lst,2); n = NRows(pos); // n = 2 |
Get Unique Elements of a List
1 2 3 4 |
lst1 = {1,5,2,3,4,2}; tmp = Associative Array(); Insert Into( tmp, lst ); lst2 = tmp << get keys; // lst2 = {1,2,3,4,5} |
Sum Items within a List
1 2 |
lst = {1,2,3}; s = Sum(lst); // s = 6 |
Apply Scalar Operations to a List
1 2 |
lst1 = {1,2,3}; lst2 = 2 * lst1; // {2,4,6} |
Apply Element-Wise Operations to a List
1 2 3 |
lst1 = {1,2,3}; lst2 = {2,4,6}; lst3 = lst1 * lst2; // {2,8,18} |
A list about lists! Love it!
You’ve remarkable information right.
What if do I have a list of values in the each cell of one column?
Clm#1
Row#1 11,5,2,5
Row# 2 12,6,3,9
How can each value listed in the cell be in its owb column?
Clm#1 Clm#2 Clm#3 Clm#4
Row#1 11 5 2 5
Row# 2 12 6 3 9
Thanks
Fabio
Sorry Fabio, I’ve not been doing a good job at looking out for comments. I’ll try and do better next time!