cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
The Discovery Summit 2025 Call for Content is open! Submit an abstract today to present at our premier analytics conference.
See how to use to use Text Explorer to glean valuable information from text data at April 25 webinar.
Choose Language Hide Translation Bar
View Original Published Thread

columns

hcarr01
Level VI

 

Hello everyone,
 
I have several columns:
1- “Average number” columns
2- “number” columns
 
with number ranging from 1 to 10,000.
 
Normally each column belonging to group (2) should also belong to group (1) and vice versa. So we should have the same number of columns in both groups. 
However, columns belonging to group 1 do not belong to group 2 and vice versa.
 
Example : "Average 730" but the "730" column does not exist.
 
The objective is to have the intersection of these 2 groups so that there are the same columns in the 2 groups.

This post originally written in French and has been translated for your convenience. When you reply, it will also be translated back to French .

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User


Re: colonnes

One option using associative arrays

Names Default To Here(1);

dt = Open("$DOWNLOADS/AA.jmp");

// build 
aa_duree = Associative Array();
aa_nonduree = Associative Array();

For Each({col_name}, dt << Get Column Names("String"),
	If(Word(1, col_name) == "durée",
		aa_duree[Word(-1, col_name)] = col_name;
	, !IsMissing(Regex(col_name, "\d+")),
		aa_nonduree[col_name] = 1;
	,
		continue()
	);
);
aa_duree_copy = aa_duree;
aa_duree_copy << Intersect(aa_nonduree);
cols_to_keep = Insert(aa_duree_copy << get keys, aa_duree_copy << get values);

aa_duree_copy2 = aa_duree;
aa_nonduree_copy = aa_nonduree;
aa_duree_copy2 << remove(aa_nonduree);
aa_nonduree_copy << remove(aa_duree);
cols_to_remove = Insert(aa_nonduree_copy << get keys, aa_duree_copy2 << get values);

show(cols_to_keep, cols_to_remove);

There are also other options, like joining stacked table(s) or using just lists

-Jarmo

View solution in original post

5 REPLIES 5
jthi
Super User


Re: colonnes

Associative array can help when making the intersection Associative Arrays in Set Operations (jmp.com) if you can make the keys look same. Or you could stack the tables, make them look similar and then perform a join. I think the most difficult part might be how you can get those lists of columns you are interested in and this depends on your data.

-Jarmo
hcarr01
Level VI

Re: columns

The columns are in the same data table.
 
Here is an example taken from my database:
undefined

 

I aim to remove the columns "duration 721", "730" and "750"

This post originally written in French and has been translated for your convenience. When you reply, it will also be translated back to French .

jthi
Super User


Re: colonnes

One option using associative arrays

Names Default To Here(1);

dt = Open("$DOWNLOADS/AA.jmp");

// build 
aa_duree = Associative Array();
aa_nonduree = Associative Array();

For Each({col_name}, dt << Get Column Names("String"),
	If(Word(1, col_name) == "durée",
		aa_duree[Word(-1, col_name)] = col_name;
	, !IsMissing(Regex(col_name, "\d+")),
		aa_nonduree[col_name] = 1;
	,
		continue()
	);
);
aa_duree_copy = aa_duree;
aa_duree_copy << Intersect(aa_nonduree);
cols_to_keep = Insert(aa_duree_copy << get keys, aa_duree_copy << get values);

aa_duree_copy2 = aa_duree;
aa_nonduree_copy = aa_nonduree;
aa_duree_copy2 << remove(aa_nonduree);
aa_nonduree_copy << remove(aa_duree);
cols_to_remove = Insert(aa_nonduree_copy << get keys, aa_duree_copy2 << get values);

show(cols_to_keep, cols_to_remove);

There are also other options, like joining stacked table(s) or using just lists

-Jarmo
hcarr01
Level VI

Re: columns

Great thank you it works!
However the columns are in the "cols_to_remove" list, how can I delete these columns directly in the data table?

This post originally written in French and has been translated for your convenience. When you reply, it will also be translated back to French .

jthi
Super User


Re: colonnes