cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
hogi
Level XIII

non-grouped column names

After grouping several important columns, I want to hide the remaining columns in the "attic".

How do I get a list of all non-grouped columns?

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: non-grouped column names

Get list of all columns, get list of grouped columns and drop grouped from the list of columns

Names Default To Here(1);

// Setup
dt = Open("$SAMPLE_DATA/Cities.jmp");
dt << group columns("xy", {:X, :y});
dt << group columns("pollutants", :Ozone :: :Lead);


collist = dt << Get Column Names("String");
grouped_list = {};
For Each({groupname}, dt << get column groups names,
	c = dt << get column group(groupname);
	groupcols = Transform Each({cr}, c, cr << get name);
	Insert Into(grouped_list, groupcols);
);

nongrouped = Set Difference(collist, grouped_list);

For Each({colname}, nongrouped,
	Column(dt, colname) << Hide(1);
);

wait(0);
-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: non-grouped column names

Get list of all columns, get list of grouped columns and drop grouped from the list of columns

Names Default To Here(1);

// Setup
dt = Open("$SAMPLE_DATA/Cities.jmp");
dt << group columns("xy", {:X, :y});
dt << group columns("pollutants", :Ozone :: :Lead);


collist = dt << Get Column Names("String");
grouped_list = {};
For Each({groupname}, dt << get column groups names,
	c = dt << get column group(groupname);
	groupcols = Transform Each({cr}, c, cr << get name);
	Insert Into(grouped_list, groupcols);
);

nongrouped = Set Difference(collist, grouped_list);

For Each({colname}, nongrouped,
	Column(dt, colname) << Hide(1);
);

wait(0);
-Jarmo
hogi
Level XIII

Re: non-grouped column names

The detour via strings makes sense : )
I wonder why is it necessary ...

 

Names Default To Here(1);

// Setup
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dd= dt << group columns("xy", {:X, :y});
ee= dt << group columns("pollutants", :Ozone :: :Lead);
Type(ee)

collist = dt << Get Column Names();
grouped_list = {};
groups= dt << get column groups names;
For Each({groupname},groups,
	groupcols= dt << get column group(groupname);
	Insert Into(grouped_list, groupcols);
);

Show(grouped_list); // list of names with ":" {:OZONE, :CO, :SO2, :NO, :PM10, :Lead, :X, :Y};
show(collist);// list of names without ":" {city, Latitude, Longitude, ... }

nongrouped = Set Difference(collist, grouped_list); // ?!?! {city, CO, Latitude, Lead, Longitude, Max deg. F Jan, NO, OZONE, PM10, POP,"pop- m"n, Region, SO2, State, X, Y}


details which are important to know:

 

  • The return value of of << group columns is a string - not a column group.
  • << get column group returns a list of columns, not a column group
  • important: THIS list of columns lists the names with leading ":"
  • compare: get column names() returns a list of names without the leading ":"
  • -> the two lists are not compatible with each other

Workarounds:

  • via String
  • via columns

 

convert to list of columns = Function ({myColList},
	Transform each({col},myColList, Name Expr(As column(dt, col)))
);

grouped_list = convert to list of columns(grouped_list); // looks like before, but is something completely different
collist = convert to list of columns(collist); //{:city, :Latitude, :Longitude, ... }

nongrouped = Set Difference(collist, grouped_list);
Show (nongrouped) // {:city, :Latitude, :Longitude, :Max deg. F Jan, :POP, :"pop- m"n, :Region, :State};

 

 

jthi
Super User

Re: non-grouped column names

When I'm dealing with columns, only thing I care about is to get them all to strings as it will avoid a massive amount of issues you will have otherwise. In my opinion, there are basically zero reason to try and deal with columns initially with anything else than strings as you can always go from string to other "column formats". And, if  there is a reason to start from something else than a string, it isn't worth it in my experience. 

-Jarmo

Recommended Articles