cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
awalts12
Level II

Concatenate subset, within a loop

I have a loop during each iteration of which I select a subset of rows.

I'm trying to concatenate those rows and then, after exiting the loop, show the list of rows selected during each loop in one list.

Basically what I have is:

cohort ={xxx, yyy, zzz};

for (i=1, i<= N items (cohort), i++,

     dt << Select Where( starts with( :subject, cohort );

     subCohort = dt << Subset( output table name( "test" ), Selected Rows( 50 ), invisible );

     freezerlist = concatenate (subCohort);

);

show(freezerlist);

From the above I get an individual window with the subset table "test" for each iteration but I can't get them to join together in one list.

Thanks for any help.

Avram

1 ACCEPTED SOLUTION

Accepted Solutions
DaveLee
Level IV

Re: Concatenate subset, within a loop

Building a little of msharp's response, maybe this is what you're looking for:

new = New Table( "FreezerList" );  // Make an empty table;

cohort = {xxx, yyy, zzz};

For( i = 1, i <= N Items( cohort ), i++,

    dt << Select Where( Starts With( :subject, cohort ), current selection( "extend" ) );

    subCohort = dt << Subset( output table name( "test" ), Selected Rows( 1 ), invisible );

    new<< Concatenate( subCohort, Append to First Table );

    Close( subCohort, NoSave );

);

View solution in original post

5 REPLIES 5
msharp
Super User (Alumni)

Re: Concatenate subset, within a loop

This is confusing, I'm not really sure what you are trying to do. (freezerlist = concatenate(subCohort)) doesn't make sense, and I can't make heads or tails since I don't know what freezerlist is.  I'm guessing it's suppose to be a data table.

Are you looping through, creating subsets, and then trying to concatenate those subsets?  In which case I want to know why you don't just do it all at once and only make one subset?

cohort ={xxx, yyy, zzz};

for (i=1, i<= N items (cohort), i++,

    dt << Select Where( starts with(:subject, cohort[i]), current selection("extend"));

);

subCohort = dt << Subset( output table name( "test" ), Selected Rows( 1 ), invisible );

freezerlist = dt << Get Selected Columns;

show(freezerlist);


Note: you can concatenate strings, lists, matrices, and data tables.

  Concat(string1, string2);

  Concat(matrix1, matrix2);

  datatable1 << Concatenate( datatable2 );



awalts12
Level II

Re: Concatenate subset, within a loop

Sorry ...

In words what i am trying to do is use a loop to read through a long table for a rows searching for a certain prefix (that changes on each loop) and several other criteria (that are static).

On each pass through the loop, certain rows are identified.

The prefix being searched for changes with each iteration but the other criteria remain the same.

What I want is to create a single list (called freezerlist) containing the rows identified in each loop.

Thanks

txnelson
Super User

Re: Concatenate subset, within a loop

Here is a working piece of code that I believe may be close to what you want......I am making the assumption you what the actual data from the selected rows, and not the row numbers.

Names Default To Here( 1 );

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

// Change the column name "name" to "subject"" to match the example

dt:name << set name( "subject" );

cohort = {"C", "J", "S"};

dt << Select Where( Starts With( :subject, cohort[1] ) );

baseDT = dt << Subset( output table name( "Test" ), selected rows( 1 ), selected columns( 0 ) );

For( i = 2, i <= N Items( cohort ), i++,

dt << Select Where( Starts With( :subject, cohort ) );

TempDT = dt << Subset( output table name( "Test" ), selected rows( 1 ), selected columns( 0 ) );

baseDT = baseDT << concatenate( TempDT, append to first table( 1 ) );

Close( TempDT, nosave );

);

freezerlist = baseDT:subject<<get values;

show(freezerlist);

Jim
DaveLee
Level IV

Re: Concatenate subset, within a loop

Building a little of msharp's response, maybe this is what you're looking for:

new = New Table( "FreezerList" );  // Make an empty table;

cohort = {xxx, yyy, zzz};

For( i = 1, i <= N Items( cohort ), i++,

    dt << Select Where( Starts With( :subject, cohort ), current selection( "extend" ) );

    subCohort = dt << Subset( output table name( "test" ), Selected Rows( 1 ), invisible );

    new<< Concatenate( subCohort, Append to First Table );

    Close( subCohort, NoSave );

);

awalts12
Level II

Re: Concatenate subset, within a loop

Thanks - this works nicely!