- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
JSL keep command to keep wanted variables and delete unwanted variables?
I am looking for a JSL script command to "keep" only specified column variables, and delete all other variables in the current data table.
This would be the inverse of the specified command: dt << Delete Columns( :A, :B, ... :N);
Ideally a more efficient keep command would appear like:
dt = Current Data Table( );
dt << Keep Columns ( :time, :day, :location );
(outcome = Delete all columns that do not equal :time, :day, :location).
Thanks.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL keep command to keep wanted variables and delete unwanted variables?
Until they add it to JSL you can try this:
Re: Deleting columns that are not in a list
it could be further developed and i found it very useful before using the table update command.
Before updating tables it is useful to remove columns that have same name but you do not wish to update. The following will do it just by defining the to keep columns.
dt10 = New Table( "Test",
Add Rows( 10 ),
New Column( "A" ),
New Column( "B" ),
New Column( "C" ),
New Column( "D" )
);
Keep = {"A", "C"};
todelete = dt10 << get column names( "string" );
For( in = 1, in <= N Items( Keep ), in++, // assuming the to keep list is shorter than the list of columns in the table.
location = Contains( todelete, Keep[in]) ; // find the location of the keepers
if (location > 0, Remove From( todelete, location, 1 ) // if found remove it
));
if (nitems (todelete) > 0, dt10 << delete columns( todelete )); // if there is a delete list delete the columns from the table
if you ask the development team for this command ask them to make the same for rows.
best
ron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL keep command to keep wanted variables and delete unwanted variables?
Thank you. Your script above was helpful.
I modified slightly to operate in current data table, eg Data Table( "name_here") compared to creating a new data table and the outcome was successful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL keep command to keep wanted variables and delete unwanted variables?
A more direct method was added to JSL in JMP 14. Select columns, invert column selection, and delete columns can accomplish what is needed.
dt = open("$SAMPLE_DATA\Big Class.jmp");
a = {"height", "weight"};
dt << select columns(a);
dt << invert column selection;
b = dt << get selected columns;
dt << delete columns(b);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL keep command to keep wanted variables and delete unwanted variables?
I assume that you are making a feature enhancement request. You will be better served if you submit this to
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL keep command to keep wanted variables and delete unwanted variables?
Until they add it to JSL you can try this:
Re: Deleting columns that are not in a list
it could be further developed and i found it very useful before using the table update command.
Before updating tables it is useful to remove columns that have same name but you do not wish to update. The following will do it just by defining the to keep columns.
dt10 = New Table( "Test",
Add Rows( 10 ),
New Column( "A" ),
New Column( "B" ),
New Column( "C" ),
New Column( "D" )
);
Keep = {"A", "C"};
todelete = dt10 << get column names( "string" );
For( in = 1, in <= N Items( Keep ), in++, // assuming the to keep list is shorter than the list of columns in the table.
location = Contains( todelete, Keep[in]) ; // find the location of the keepers
if (location > 0, Remove From( todelete, location, 1 ) // if found remove it
));
if (nitems (todelete) > 0, dt10 << delete columns( todelete )); // if there is a delete list delete the columns from the table
if you ask the development team for this command ask them to make the same for rows.
best
ron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL keep command to keep wanted variables and delete unwanted variables?
Thank you. Your script above was helpful.
I modified slightly to operate in current data table, eg Data Table( "name_here") compared to creating a new data table and the outcome was successful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL keep command to keep wanted variables and delete unwanted variables?
Probably a simpler solution that is easy to do manually (and script easily) is to just subset your data.
Select the Columns you want to keep and then subset with the Selected Columns(1) option. This should also be faster than the method described above when the data table gets large, but I haven't tested it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: JSL keep command to keep wanted variables and delete unwanted variables?
A more direct method was added to JSL in JMP 14. Select columns, invert column selection, and delete columns can accomplish what is needed.
dt = open("$SAMPLE_DATA\Big Class.jmp");
a = {"height", "weight"};
dt << select columns(a);
dt << invert column selection;
b = dt << get selected columns;
dt << delete columns(b);