cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
awsmagala
Level II

Creating a list of Column References

I am trying to make a list of column references to later use in making a stacked data table.

When I make the list inside a function it works perfectly fine.  However, when I try the same inside a class method it does not work yielding the error message: "No value to Op Assign"(1, 2).

 

make_col_list = Function({dt,start,end},
	Local({lst,col_list},
		Try(
			Current Data Table(dt);
			col_list = {};
			lst = dt << Get Column Names;
			For(i=start,i<=end,i++,
				Insert Into(col_list,lst[i])
			);
		,
			Throw("Error in col_list: "||char(exception_msg))
		);
		col_list;
	);
);

Above is the function I use in one script.  This function currently works no issues.

 

When I try a similar idea inside of a class however it will not work.  Below is how I have it defined inside of the class.

 

col_list = dt << Get Column Names;
show(col_list);
show(col_list[26]);
Try(
	For(pv_i=27,pv_i<=696,i++,
		show(col_list[pv_i]);
		Insert Into(pv_lst,col_list[pv_i]);
	);
,
	Throw("Error in pv columns: "||Char(exception_msg));
);
Try(
	For(zv_i=16,zv_i<=25,zv_i++,
		Insert Into(zv_lst,col_list[zv_i]);
	);
,
	Throw("Error in zv columns: "||Char(exception_msg));
);
Try(
	For(wr_i=26,wr_i<=361,wr_i++,
		Insert Into(wr_lst,col_list[wr_i]);
	);
,
	Throw("Error in work columns: "||Char(exception_msg));
);
Try(
	For(dr_i=362,dr_i<=696,dr_i++,
		Insert Into(dr_lst,col_list[dr_i]);
	);
,
	Throw("Error in drive columns: "||Char(exception_msg));
);

I have multiple groups of columns I am trying to select and manipulate.

I originally tried to use a method like this: 

pv_lst = Column(26::696);

but was unable to get this to work either.

 

Any help in how to properly generate a list or collection of column references would be great.

 

 

1 REPLY 1
cwillden
Super User (Alumni)

Re: Creating a list of Column References

Hi @awsmagala,

It sounds like you are trying to do something relatively simple in a very complicated way.  You can do a table stack with a list of column numbers instead of the explicit column names.  For example, I can stack all the numeric columns in Car Physical Data (sample data table) the usual way like so:

Data Table( "Car Physical Data" ) << Stack(
	columns( :Weight, :Turning Circle, :Displacement, :Horsepower, :Gas Tank Size ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" )
)

Or in the columns argument, I can do this:

stack_cols = 4::8;

Data Table( "Car Physical Data" ) << Stack(
	columns( stack_cols ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" )
);

If the columns you want to stack are not all together, you can just concatenate the chunks of column numbers together.  Hopefully that helps.

Also, if you want to get the actual column names in a range, you could really shorten that make_col_list function to something like:

col_names = (dt << Get Column Names)[start::end]
-- Cameron Willden