Subscribe Bookmark RSS Feed

selecting multiple rows defined by col var

saitcopuroglu

Community Trekker

Joined:

Sep 29, 2014

Hi all,

I've found this script from one of the on-demand webcast data dt1 << Select Where( :Term == "Intercept" ); and adapting it to my data table the result is:

..... << Select Where( :SOURCE == "Facebook");


  • but how will I choose more than one (Facebook and Zoover and Tripadvisor...)
  • how will I clear the selection and make another selection
  • how will I invert the selection

Many thanks

8957_2015-06-18_12-41-04.png


1 ACCEPTED SOLUTION

Accepted Solutions
Solution

The example code below may give some ideas (the Wait(1) commands are only for demo purpose);

dt = New Table("demo", New Column("X", character, values({"a", "b", "c", "d", "q", "a", "b", "c", "d"})));

my_list = {"a", "c", "q"};

Wait(1);

dt << select where(Contains(my_list, :X));// Select all items in my_list

Wait(1);

dt << select where(Contains(my_list[1 :: 2], :X));//By default need to clear before making another selection

Wait(1);

dt << invert row selection; // Invert selection

Wait(1);

dt << clear select;// Clear selection

5 REPLIES
Solution

The example code below may give some ideas (the Wait(1) commands are only for demo purpose);

dt = New Table("demo", New Column("X", character, values({"a", "b", "c", "d", "q", "a", "b", "c", "d"})));

my_list = {"a", "c", "q"};

Wait(1);

dt << select where(Contains(my_list, :X));// Select all items in my_list

Wait(1);

dt << select where(Contains(my_list[1 :: 2], :X));//By default need to clear before making another selection

Wait(1);

dt << invert row selection; // Invert selection

Wait(1);

dt << clear select;// Clear selection

saitcopuroglu

Community Trekker

Joined:

Sep 29, 2014

Thank you MS, I fell short to understand the second command, does it choose the 1st and 2nd values by order? No.. Does it select 1st and and 3rd by adding up 2?

What would be the command If I happen to have a second column (:Y) (with the second selection named as my_selection2) and would like to select the both together my_selection & my_selection2 ?

Many thanks for your support.

saitcopuroglu

Community Trekker

Joined:

Sep 29, 2014

I've understood the second command, it chooses the 1st and 2nd of my selection list and the third and fourth goes as [1 :: 2 :: 3 :: 4]?, many thanks

ms

Super User

Joined:

Jun 23, 2011

To adress multiple items of a list using an index [...] an matrix should be used.

my_list[1]; //First item

my_list[[1, 3]]; //First and third items

my_list[[1 2 3]]; //First to third items

my_list[1::3]; // Same thing

The double colon is short for Index(), i.e. it creates a matrix with a range of integers.

1::2 equals the matrix [1 2]

ms

Super User

Joined:

Jun 23, 2011

Exactly so! Use the "&" command to combine selection criteria.

dt << select where(Contains(..., :X) & Contains(..., :Y));