cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Thierry_S
Super User

Scripting > List > Remove Missing Values

Hi JMP Team,

I'm looking for a method to remove missing / empty values from a List generated within a script:

The initial List looks like: {.,.,.,2,3,4,7,.,.,.} and I would like to end up with a new List = {2,3,4,7}.

Any ideas how to achieve that without relying on a a loop through the List elements?

Thanks.

Best,

TS 

Thierry R. Sornasse
2 ACCEPTED SOLUTIONS

Accepted Solutions
Ryan_Gilmore
Community Manager Community Manager

Re: Scripting > List > Remove Missing Values

Hi @Thierry_S ,

 

Try this,

 

x = {.,.,.,2,3,4,7,.,.,.};
remove(x, as list(loc(x, .)));

View solution in original post

ian_jmp
Staff

Re: Scripting > List > Remove Missing Values

Alternatively:

NamesDefaultToHere(1);

in = {.,.,.,2,3,4,7,.,42,.};
out = in[LocNonMissing(in)];
Print(out);

View solution in original post

7 REPLIES 7
Ryan_Gilmore
Community Manager Community Manager

Re: Scripting > List > Remove Missing Values

Hi @Thierry_S ,

 

Try this,

 

x = {.,.,.,2,3,4,7,.,.,.};
remove(x, as list(loc(x, .)));
ian_jmp
Staff

Re: Scripting > List > Remove Missing Values

Alternatively:

NamesDefaultToHere(1);

in = {.,.,.,2,3,4,7,.,42,.};
out = in[LocNonMissing(in)];
Print(out);
Thierry_S
Super User

Re: Scripting > List > Remove Missing Values

Hi Ian,
Nice touch with adding "42" to the list: let's stay clear of the Vogon
Best,
TS
Thierry R. Sornasse
Valerio
Level II

Re: Scripting > List > Remove Missing Values

Hi Ryan,

I don't know why but your script does not work for me... (I have JMP 16, in case it can help to debug the issue)

pmroz
Super User

Re: Scripting > List > Remove Missing Values

Can you supply a code snippet and the error message?

 

If your list contains character strings then loc will not work - it's only for numbers.  

 

Here's a solution for a list of strings with empty values.

a = {"a", "", "b", "", "c", "d", "e"};
b = concat items(a, ";");
c = words(b, ";");

Challenge: anyone with an alternate solution?

vince_faller
Super User (Alumni)

Re: Scripting > List > Remove Missing Values

In case you already haven't figured it out.  it does work but it only returns a copy.  if you want to alter x you'd have to either reassign it or use removefrom()

 

Names default to here(1);
x = {.,.,.,2,3,4,7,.,.,.};
new_x = remove(x, as list(loc(x, .)));
show(x, new_x);
removefrom(x, as list(loc(x, .)));
show(x, new_x);
Vince Faller - Predictum

Re: Scripting > List > Remove Missing Values

Also,

 

Names Default to Here( 1 );

original = [.,.,.,2,3,4,7,.,.,.];

none missing = original[Loc( Not( Is Missing( original ) ) )];