cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
mohammed1405
Level I

how can I generate subset table

Hello,

I have a table which contains 8 columns and I want to choose each two columns to be together for example ( column 1 with column 2,column 1 with column 3, until column 1 with column 8) then start with column 2 with column 3 until column 2 with column 8..... and finish with column 7 with column 8.

i tried to use sebset but i faced a problem when i tried to make them as in general. 

 this is what i did

 

dt2_5_2=New Table( "First Example",
 Add Rows( 17 ),
 New Column( "Column 1",
  Numeric,
  "Continuous",
  Format( "Best", 12 ),
  Set Values( [1, 0, 0, 0, -1, -1, -1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1] )
 ),
New Column( "Column 2",
  Numeric,
  "Continuous",
  Format( "Best", 12 ),
  Set Values( [-1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1] )
 ),
 New Column( "Column 3",
  Numeric,
  "Continuous",
  Format( "Best", 12 ),
  Set Values( [-1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1] )
 ),
 New Column( "Column 4",
  Numeric,
  "Continuous",
  Format( "Best", 12 ),
  Set Values( [-1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1] )
 ),
 New Column( "Column 5",
  Numeric,
  "Continuous",
  Format( "Best", 12 ),
  Set Values( [-1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1] )
 ),
 New Column( "Column 6",
  Numeric,
  "Continuous",
  Format( "Best", 12 ),
  Set Values( [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1] )
 ),
 New Column( "Column 7",
  Numeric,
  "Continuous",
  Format( "Best", 12 ),
  Set Values( [-1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1] )
 ),
 New Column( "Column 8",
  Numeric,
  "Continuous",
  Format( "Best", 12 ),
  Set Selected,
  Set Values( [1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1] )
 ),
 Set Row States( [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] )
);

for (i=1,i<=8,i++,
    for (j=i+1,j<=8,j++,
      subDt1 = dt2_5_2 << Subset(Columns([1,8]), Output Table Name("Sub"));
      eval(subDt1)
));

 

i tried to make subset in general by using i and j but unfortunately did not work. 

 

  (Subset(Columns([i,j]), Output Table Name("Sub"));)

so when i put number [1,8] then gave me 28 time same two numbers.

i hope someone can help me and thank you for your considration

Mohammed 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Level X

Re: how can I generate subset table

Using the 'looping' idea, you could try:

NamesDefaultToHere(1);

dt = DataTable("First Example");
cols = dt << getColumnNames;

for(c1 = 1, c1<= NItems(cols), c1++,
	for(c2 = c1+1, c2 <= NItems(cols), c2++,
		dt << Subset(Columns(cols[c1], cols[c2]));
	);
);

View solution in original post

4 REPLIES 4
uday_guntupalli
Level VIII

Re: how can I generate subset table

@mohammed1405
        It might be easier to think of subsetting using selected rows and columns and then expand it into a loop. Let me provide an example . 

 

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

dt << Select Randomly(0.3); 

dt1 = dt << Subset(Selected Rows(1),Selected Columns(0)); // Subsetting rows 

dt << Clear Selection ; 

dt << Select Columns({"city","State","Region"}); 

dt2 = dt << Subset(Selected Rows(0),Selected Columns(1)); // Subsetting columns 
Best
Uday
mohammed1405
Level I

Re: how can I generate subset table

 I have tried using selected rows but unfortunately did not work for me. 

thanks a lot for reply

ian_jmp
Level X

Re: how can I generate subset table

Using the 'looping' idea, you could try:

NamesDefaultToHere(1);

dt = DataTable("First Example");
cols = dt << getColumnNames;

for(c1 = 1, c1<= NItems(cols), c1++,
	for(c2 = c1+1, c2 <= NItems(cols), c2++,
		dt << Subset(Columns(cols[c1], cols[c2]));
	);
);
mohammed1405
Level I

Re: how can I generate subset table

thank you a lot jan that what i am looking for 

appreciate your time