Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
Melissa
Level I

How do I reference to a column by column number in jsl when column number is a variable?

Hi,

I'm having trouble subsetting columns.  In the code below, I'm looking to create multiple new data tables (and perform some analyses with them- though I deleted that part of the script) from my current table. My current table is formatted with one "X" column (column 1) and several "Y" columns (columns 2 through ncols(dt). I'm having an issue where the columns() function does not recognize icol as a variable representing a number (I assume it's looking for a column named icol). Is there a fix for this?

 

dt=current data table();
For( icol = 2, icol <= ncols(dt) , icol++,
	dt << Subset( All rows, columns( 1, icol  ))
) 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
ron_horne
Super User

Re: How do I reference to a column by column number in jsl when column number is a variable?

Hi @Melissa 

try this method,

 

Names Default To Here( 1 );

dt = Current Data Table();
icol = dt << Get Column Names();

For( i = 2, i <= N Items( icol ), i++,
	dt1 = dt << subset( all rows, columns( 1, icol[i] ),
		output table( "subset - " || Char( icol[i] ) ), 
		
	)
);

 

 

 

let us know if it works for you.

ron

 

View solution in original post

2 REPLIES 2
Highlighted
ron_horne
Super User

Re: How do I reference to a column by column number in jsl when column number is a variable?

Hi @Melissa 

try this method,

 

Names Default To Here( 1 );

dt = Current Data Table();
icol = dt << Get Column Names();

For( i = 2, i <= N Items( icol ), i++,
	dt1 = dt << subset( all rows, columns( 1, icol[i] ),
		output table( "subset - " || Char( icol[i] ) ), 
		
	)
);

 

 

 

let us know if it works for you.

ron

 

View solution in original post

Highlighted
Melissa
Level I

Re: How do I reference to a column by column number in jsl when column number is a variable?

Thanks! that's exactly what I was looking for.
Article Labels

    There are no labels assigned to this post.