BookmarkSubscribeSubscribe to RSS Feed
qt

Community Trekker

Joined:

Oct 17, 2012

loop through columns with similar names

Hi, JMP experts,

Is there an easier way to loop through JMP data file with many columns?

My data file has columns:

Err_Loc_0_Time_0

Err_Loc_0_Time_1

Err_Loc_0_Time_2

Err_Loc_0_Time_3

....

Err_Loc_0_Time_20

Err_Loc_1_Time_0

Err_Loc_1_Time_1

Err_Loc_1_Time_2

.....

Err_Loc_1_Time_20

Err_Loc_2_Time_0

.....

Err_Loc_30_Time_20

So Loc can change from 0-30, Time change from 0-20.

If I want to do a transpose:

Data Table( data_table ) << Transpose(

columns(

:Err_Loc_0_Time_0

:Err_Loc_0_Time_1

:Err_Loc_0_Time_2

:Err_Loc_0_Time_3

....

:Err_Loc_0_Time_20

:Err_Loc_1_Time_0

:Err_Loc_1_Time_1

:Err_Loc_1_Time_2

.....

:Err_Loc_1_Time_20

:Err_Loc_2_Time_0

),

);

So I have to copy and paste the column name one by one, can I use some I, J loop?

For I=0,30

For J=0,20

:Err_Loc_I_Time_J

....

Can somebody please tell me how to do this?

Thanks,

Qian

2 REPLIES
ms

Super User

Joined:

Jun 23, 2011

Re: loop through columns with similar names

Transpose can use a list of columns, so something like this should work:

dt = Current Data Table();

col_list = {};

For( i = 0, i <= 30, i++,

  For( j = 0, j <= 20, j++,

  Insert Into( col_list, Parse( ":Err_Loc_" || Char( i ) || "_Time_" || Char( j ) ) )

  )

);

dt << Transpose( columns( Eval( col_list ) ) );

qt

Community Trekker

Joined:

Oct 17, 2012

Re: loop through columns with similar names

MS, thanks!

It works.

It is very cool we can loop through columns with index.

Best regards,

Qian