Subscribe Bookmark RSS Feed

How to place List values into the column

miguello

Community Trekker

Joined:

Jan 27, 2016

As a result of some manipulations I have a list of size of number of rows in my table.

I want to create a new column and place these values into this colum.

JSL reference says that this should work:

 

dt = New Table( "My Data");
dt << New Column( "Last Name", Character, Values( {"Smith", "Jones",
"Anderson"} ) );

 

 

IThe list that I want to put into that column is actually list of lists. If I do Eval(names) I get something like {{"John"}, {"Jim" },{"Jane"}}

How to make it one dimensional list to put into the column?

 

Thanks!

5 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

This should do it:

Names Default To Here( 1 );
origlist = {{"John"}, {"Jim"}, {"Jane"}};
newlist = {};
For( i = 1, i <= N Items( origlist ), i++,
	Insert Into( newlist, origlist[i] )
);
dt = New Table( "My Data" );
dt << New Column( "Last Name", Character, Values( newlist ) );
Jim
miguello

Community Trekker

Joined:

Jan 27, 2016

Jim,

Wouldn't it just take the items in the first list (which are already lists) into new list (also in the form of one-tem-lists)?

Anyways, I couldn't find a way to fight it when list already formed, but I did it like this:

In the loop that constracts my list of lists, I have something like this:

for(t=1, t<=NItems(....)....
......
names[t] = someFunctionThatSpitsSingleNameLists[i][j];
);

I do this:

 

 

names[t] = Item(2,Char(someFunctionThatSpitsSingleNameLists[rowTool][rowcurrentReplacementDate]), "\!"");

It just evaluates those single name lists like "{"Jim"}" and then takes only Jim - and puts it in names[t] list.

 

maurogerber

Community Trekker

Joined:

May 25, 2016

disregard

txnelson

Super User

Joined:

Jun 22, 2012

Your code does work, however the issue is that the list, "Origlist" is a list of lists, not just a single list, which is the way your have the list defined in your script.  So the issue is, how to get the list of lists into the data table.

Jim
Phil_Brown

Super User

Joined:

Mar 20, 2012

Following on @txnelson post...I actually created a little function to do this, as I found myself in the same position many times. This will "flatten" list of lists 2 levels deep for example.

 

Flatten2DList = Function( {list_arg},
	{DefaultLocal},
	NewList = {};
	For( i = 1, i <= N Items( list_arg), i++, 
		For( j = 1, j <= N Items( list_arg[i] ), j++, 
			Insert Into( NewList, list_arg[i][j] );
		);
	);
	NewList;
)
PDB