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
Dave0416
Level I

Want to create table showing all possible combinations from x & y position vectors

I am provided 2 position vectors xpos and ypos.  I want to create table showing all possible combinations from the x & y position vectors. I'm showing a very simple example where I want to create 2 new vectors containing all possible combinations. My issue appears to stem from the indexing but I'm stumped.  

// Want to create table showing all possible combinations from x & y position vectors

xpos={1, 2, 3, 4, 5};
ypos={7, 8, 9 };

xloc={};
yloc={};

// Loop through x positions
for(i=1, i<=NItems(xpos), i++,
	// Loop through y positions
	for(j=1, j<=NItems(ypos),j++,
		insert into(xloc, xpos);
		insert into(yloc, ypos, j);
	);	
	//print(i);
);
	
xloc;
yloc;

dt = new table("All Combos");
dt << new column("X", continuous, values(xloc));
dt << new column("Y", continuous, values(y));

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	Want a table that looks like this:
	X	Y
	1	7
	1	8
	1	9
	2	7
	2	8
	2	9
	.
	.
	.
	5	7
	5	8
	5	9
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Want to create table showing all possible combinations from x & y position vectors

I would just use 

     Tables=>Join

and use the Cartesian Join capabilities to get what you want.

txnelson_0-1680535169909.png

names default to here(1);
xpos={1, 2, 3, 4, 5};
ypos={7, 8, 9 };

dt1 = new table("One", new column("x"));
dt1:x << set values(xpos);
dt2 = new table("Two", new column("y"));
dt2:y << set values(ypos);

dtCart = dt1 << Join(
	With( dt2 ),
	Cartesian Join,
	Output Table( "Final" )
);
Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: Want to create table showing all possible combinations from x & y position vectors

I would just use 

     Tables=>Join

and use the Cartesian Join capabilities to get what you want.

txnelson_0-1680535169909.png

names default to here(1);
xpos={1, 2, 3, 4, 5};
ypos={7, 8, 9 };

dt1 = new table("One", new column("x"));
dt1:x << set values(xpos);
dt2 = new table("Two", new column("y"));
dt2:y << set values(ypos);

dtCart = dt1 << Join(
	With( dt2 ),
	Cartesian Join,
	Output Table( "Final" )
);
Jim
Dave0416
Level I

Re: Want to create table showing all possible combinations from x & y position vectors

Thank you! I got so wrapped around the axle that I forgot about your solution. Can I blame my lapse on today being Monday?