cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
nikles
Level VI

Possible to assign a list of items to part of a column?

Hi.  I was wondering if there's a clever way to assign or append a list of items to column(s) in an existing table.  For example, I have a column of names and I would like to add more names (rows) to the column from a list.  The code below was one of my attempts.  The problem is that instead of assigning each item in the list to its own row, rows 1-6 are each assigned the entire list.

 

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << Add Rows(6, At Start);
dt:name[1::6] = {"A", "Very", "Long", "List", "Of", "Items"};

 

I'm aware that I could add a list of "column = value" pairs using the << Add Rows() message, but this requires me to modify my existing column of items from {"item1", "item2", ...} to {column name = "item1", column name = "item2", ....}.  Perhaps there's some command that converts the one list format to the other format?  I can see no straightforward way to do this that doesn't rely on a For loop.  

 

Also have considered just creating a temp table with the same column names, using << Set Values(list) to populate the columns, and then concatenating to the original table.  For various reasons though, I'd prefer not to do it this way. 

 

Lastly, I considered reading all the original column values back as lists, appending the new list for each column to the originals, and then just writing each entire list back to the original table.  Again, not my preferred method as my lists are long.  

 

Is there some other way I could do this?  Thanks.

 

Using JMP Pro 17.0.0 on Mac OS Ventura 13.2.1

2 ACCEPTED SOLUTIONS

Accepted Solutions
vince_faller
Super User (Alumni)

Re: Possible to assign a list of items to part of a column?

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << Add Rows(6, At Start);
dt[1::6, "name"] = {"A", "Very", "Long", "List", "Of", "Items"};
Vince Faller - Predictum

View solution in original post

txnelson
Super User

Re: Possible to assign a list of items to part of a column?

You can get what you want by using "Set Values".

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Add Rows( 6, At Start );
theList = {"A", "Very", "Long", "List", "Of", "Items"};
dt:name << set values( theList );
Jim

View solution in original post

6 REPLIES 6
hogi
Level XI

Re: Possible to assign a list of items to part of a column?

edit:

According to Data-table-subscripting one can use:

dt[1::6,{name}] = {{"A"}, {"Very"}, {"Long"}, {"List"}, {"Of"},{ "Items"}};

or

dt[1::6,{name,sex}] = {{"A","F"}, {"Very","M"}, {"Long","F"}, {"List","M"}, {"Of","F"},{ "Items","M"}};

 

For numbers it's just:

dt[1::6,{height}] = [6,5,4,3,2,1 ];

 

Re: Possible to assign a list of items to part of a column?

You can also use functions of lists.

 

Names Default to Here( 1 );

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

:name << Set Values(
	Insert(
		(:name << Get Values),
		{ "name 41", "name42" }
	)
);
vince_faller
Super User (Alumni)

Re: Possible to assign a list of items to part of a column?

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << Add Rows(6, At Start);
dt[1::6, "name"] = {"A", "Very", "Long", "List", "Of", "Items"};
Vince Faller - Predictum
hogi
Level XI

Re: Possible to assign a list of items to part of a column?

Ah, thanks!

interesting:

dt[1::6,{name}]; // {{"KATIE"}, {"LOUISE"}, {"JANE"}, {"JACLYN"}, {"LILLIE"}, {"TIM"}}
dt[1::6,"name"]; // {"KATIE", "LOUISE", "JANE", "JACLYN", "LILLIE", "TIM"} 
dt[1::6,{height}]; // [59, 61, 55, 66, 52, 60]
dt[1::6,"height"]; // [59, 61, 55, 66, 52, 60] (same)

and therefore one needs to write:

dt[1::6,{name}] = {{"KATIE"}, {"LOUISE"}, {"JANE"}, {"JACLYN"}, {"LILLIE"}, {"TIM"}}
dt[1::6,"name"] =  {"KATIE", "LOUISE", "JANE", "JACLYN", "LILLIE", "TIM"}
dt[1::6,"height"]=[1,2,3,4,5,6]
dt[1::6,{height}]=[1,2,3,4,5,6]	

... I didn't know.

nikles
Level VI

Re: Possible to assign a list of items to part of a column?

Thanks Vince.  I knew there was a way.  I like this method the most since I can tailor the code insert values to any row, even if they aren't contiguous:

 

Names Default To Here( 1 );
Try(Close("Big Class.jmp", NoSave));
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Add Rows( 2, After(2) );
dt << Add Rows( 2, After(7) );
dt << Add Rows( 2, After(12) );
dt[[3 4 8 9 13 14], "name"] = {"A", "Very", "Long", "List", "Of", "Items"};

nikles_0-1680621793897.png

Kudos!

txnelson
Super User

Re: Possible to assign a list of items to part of a column?

You can get what you want by using "Set Values".

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt << Add Rows( 6, At Start );
theList = {"A", "Very", "Long", "List", "Of", "Items"};
dt:name << set values( theList );
Jim