Choose Language Hide Translation Bar
MargauxR
Level II

Using columns as variable

Hello Everybody !

This is my first post, but not the last i hope!

 

I'm working on tasting results. Tasters put samples in different groups, if the letter is the same, samples are in the same group. the first colum is the ref of the sample and after i have a colum by taster. I have a table like that :

NUM ECH    D1   D2   D3

123               A      A      B

234               A      B      B

345               B      B     C

 

I would like to have a new table by taster, with 0 if samples are in the same groupe and 1 if they are not.

For the first taster the new table is :

NUM ECH    123     234     345

123                0        0          1

234                0        0          1

345                1        1          0

 

I don't have any trouble to create this new table for one taster, but i would like to all taster, so for all colums. At the end, i have to sum all the table to have distance between samples.

For that, i don't really know how to use colums as variable, if it's possible or not ...

May you help me ?

i'm begining to script in JMP !

Thank you for your help !

 

 

Margaux

 

Margaux R
5 REPLIES 5
Highlighted
gzmorgan0
Super User

Re: Using columns as variable

@MargauxR ,

 

Your problem was interesting, even though I found your resulting table strange: it loses the grade/group values!

Taster D1 and D5 might group the samples identically but D1 give them an A and D5 a C?

 

Oh well!  I expanded your sample table. This tableand the script is attached. I think it does what you want. 

 

If you are new to JSL, you need to use Help>Scripting Index to look up JSL table messages like Get Rows Where() and Add Rows, ncol(dt), Sort, etc..

image.png

image.png

 

Highlighted
MargauxR
Level II

Re: Using columns as variable

@gzmorgan0 

Thank you very much for your answer ! it looks to work ! I didn't think to work in that way ...

I will try on my tablea tomoorow, i'll tell you if everything is good.

About my table, i have made it easy than it is. In fact, each letter match with a group of word to describ the group. But i can manage that part  

Thank you again !

Margaux R
Highlighted
MargauxR
Level II

Re: Using columns as variable

Hello Everybody

I still have a problem. I tried to change a bit the code, because my groups will be name differently by taster.

It almost works, but i have a problem of repetition. If the taster put several sample in the same groupe, so with the same "name", the script will add several lines, in relation with the number of time the name is repeated.

At the and, i just want one line by sample.

I can't find where is the mystake ...

I do the script on the table "tasters" and the result is "taster match 3"

May you help me ?

 

Margaux R
Highlighted
gzmorgan0
Super User

Re: Using columns as variable

@MargauxR,

 

The first script I attached did not meet your stated goal.  If this table meets your needs, the modified script is attached.

image.png   

dt = Data Table("Tasters");

samples = dt:NUM ECH << get values;
nsamp = nitems(samples);

dtnew = New Table("Taster Match", New Column("Taster", Character),
            New Column("NUM ECH", character));
for(l=1, l<= nsamp, l++,
	dtnew << New Column(samples[l], Numeric)
);

vec = J(nsamp, 1, 1);
//get taster info
currRow = 0;
for(i= 2, i<=ncol(dt), i++,
   tester = column(dt,i) << get name;
      for(j = 1, j<=nsamp, j++,
      idx = dt << get rows where (column(dt,i)[]==column(dt,i)[Row()=j]);
      nr = nrow(idx);
      tvec = vec;
      if(nr > 0, 
        tvec[idx] = 0;
      );
	  dtnew << add row(1);
      currRow++;
      dtnew:Taster[currRow] = tester;
      dtnew:NUM ECH[currRow] = samples[j];
      //write out results
      dtnew[currRow,3::nsamp+2] = Transpose(tvec); 
  );  //end for j
);    // end for i
Highlighted
MargauxR
Level II

Re: Using columns as variable

Thank you very much, it works perfectly !

In fact, the last loop is usefull.

i never used vector before, that a good help !

 

Margaux R
Article Labels