Choose Language Hide Translation Bar
saitcopuroglu
Community Trekker

selecting multiple rows defined by col var

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


0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User ms
Super User

Re: selecting multiple rows defined by col var

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

View solution in original post

0 Kudos
5 REPLIES 5
ms
Super User ms
Super User

Re: selecting multiple rows defined by col var

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

View solution in original post

0 Kudos
saitcopuroglu
Community Trekker

Re: selecting multiple rows defined by col var

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.

0 Kudos
saitcopuroglu
Community Trekker

Re: selecting multiple rows defined by col var

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

0 Kudos
ms
Super User ms
Super User

Re: selecting multiple rows defined by col var

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]

0 Kudos
ms
Super User ms
Super User

Re: selecting multiple rows defined by col var

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

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

0 Kudos