cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
gianpaolo
Level IV

remove elements in a list

Hello,

someone can help me.....i have two lists like this:

 

MYLIST = {:empty, :empty2, :Name("A:k"), :Name("A:m"), :Name("A:x"), :Name("A:y"), :NA, :Name("D:3"), :Name("D:6"), :Name("D:8")};
DELCOLS= {:empty, :empty2};

 

 

i would like remove the elements of list DELCOLS from MYLIST

 

expected results:

 

 MYLIST = {:Name("A:k"), :Name("A:m"), :Name("A:x"), :Name("A:y"), :NA, :Name("D:3"), :Name("D:6"), :Name("D:8")}  

 

thanks in advance

Gianpaolo

Gianpaolo Polsinelli
1 ACCEPTED SOLUTION

Accepted Solutions
Jeff_Perkinson
Community Manager Community Manager

Re: remove elements in a list

@txnelson is right, the Scripting Index and Scripting Guide are excellent resources.

 

To help you along the way though, check out the For() loop, Remove From(), As List() and Loc() functions.

 

 

MYLIST = {:empty, :empty2, :Name( "A:k" ), :Name( "A:m" ), :Name( "A:x" ), :Name( "A:y" ), :NA,
:Name( "D:3" ), :Name( "D:6" ), :Name( "D:8" )};
DELCOLS = {:empty, :empty2};

For( i = 1, i <= N Items( delcols ), i++,
	Remove From( mylist, As List( Loc( mylist, delcols[i] ) ) )
);

 

-Jeff

View solution in original post

3 REPLIES 3
txnelson
Super User

Re: remove elements in a list

You would use the Remove() function. See the scripting index

     Help==>Scripting Index

for details.

I strongly suggest you read the Scripting Guide.  It contains a detail on how to manipulate lists

     Help==>Books==>Scripting Guide

Jim
Jeff_Perkinson
Community Manager Community Manager

Re: remove elements in a list

@txnelson is right, the Scripting Index and Scripting Guide are excellent resources.

 

To help you along the way though, check out the For() loop, Remove From(), As List() and Loc() functions.

 

 

MYLIST = {:empty, :empty2, :Name( "A:k" ), :Name( "A:m" ), :Name( "A:x" ), :Name( "A:y" ), :NA,
:Name( "D:3" ), :Name( "D:6" ), :Name( "D:8" )};
DELCOLS = {:empty, :empty2};

For( i = 1, i <= N Items( delcols ), i++,
	Remove From( mylist, As List( Loc( mylist, delcols[i] ) ) )
);

 

-Jeff
ms
Super User (Alumni) ms
Super User (Alumni)

Re: remove elements in a list

Jeff's code is great and use a clever way to remove any multiple instances of the unwanted items.

 

Just to illustrate that there's often more than one way to do things in JSL: here's an alternative approach using Associative Arrays. 

(Note, all multiples would be removed)

MYLIST = {:empty, :empty2, :Name("A:k"), :Name("A:m"), :Name("A:x"), :Name("A:y"), :NA, :Name("D:3"), :Name("D:6"), :Name("D:8")};
DELCOLS = {:empty, :empty2};

// Remove DELCOLS from MYLIST. Retains original order of items. 
AA = Associative Array(MYLIST, 1 :: N Items(MYLIST));
MYLIST = (AA << Remove(Associative Array(DELCOLS)) << get keys)[Rank(AA << get values)];

// If order is not important, this simpler version works (items sorted alphabetically)
MYLIST_sorted = Associative Array(MYLIST) << Remove(Associative Array(DELCOLS)) << get keys;

Show(MYLIST, MYLIST_sorted);