cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
miguello
Level VI

How to place List values into the column

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!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to place List values into the column

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

View solution in original post

5 REPLIES 5
txnelson
Super User

Re: How to place List values into the column

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
Level VI

Re: How to place List values into the column

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
Level III

Re: How to place List values into the column

disregard

txnelson
Super User

Re: How to place List values into the column

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 (Alumni)

Re: How to place List values into the column

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