Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Re: Concatenate subset, within a loop

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Dec 29, 2015 10:52 AM
(9383 views)

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

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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 );

);

5 REPLIES 5

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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 **)**;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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

Highlighted

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

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 );

);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Re: Concatenate subset, within a loop

Thanks - this works nicely!