I have tables that have data in the following order:
I want all the tables to look like this:
How can I achieve this in jsl?
@Aam_jmp, In your specific example, the following would work:
Clear Log(); Clear Globals(); dt = Current Data Table(); dt2 = (dt << Tabulate( Set Format( N( 9, "Best" ) ), Add Table( Column Table( Analysis Columns( :Age, :Height, :Weight ) ), Column Table( Grouping Columns( :Result ) ), Row Table( Grouping Columns( :Name ) ) ) ) ) << Make Into Data Table; dt2 << New Column("Result",Character,Nominal,Formula(If(:Fail==1,"Fail",If(:Pass==1,"Pass"))));
However, you will have to adjust the last column every single time in this approach. A more generalized approach is shown below:
Clear Log(); Clear Globals(); dt = Current Data Table(); CharValsAA = Associative Array(dt:Result); Results = CharValsAA << Get Keys; for(i = 1, i < N Items(Results), i++, If(!IsMissing(Results[i]), , Remove From(Results,i); ); ); dt2 = (dt << Tabulate( Set Format( N( 9, "Best" ) ), Add Table( Column Table( Analysis Columns( :Age, :Height, :Weight ) ), Column Table( Grouping Columns( :Result ) ), Row Table( Grouping Columns( :Name ) ) ) ) ) << Make Into Data Table; nR = N Rows(dt2); // Short sighted approach //dt2 << New Column("Result",Character,Nominal,Formula(If(:Fail==1,"Fail",If(:Pass==1,"Pass")))); // Generalized Approach dt2 << New Column("Test",Character,Nominal, Set Each Value("a")); for(i = 1, i <= N Items(Results), i++, VarName = Results[i]; Eval(Parse(Eval Insert("\[ Temp_^i^ = Loc(dt2:^VarName^ << Get Values) ; ]\" ))); Eval(Parse(Eval Insert("\[ for(r = 1, r <= N Rows(Temp_^i^), r++, If(Temp_^i^[r] > 0, dt2:Test[Temp_^i^[r]] = Results[^i^]; ); ) ; ]\" ))); );
@Aam_jmp, Use Summarize or tabulate
dt = Current Data Table(); dt1 = (dt << Tabulate( Add Table( Column Table( Analysis Columns( :Age, :Height, :Weight ) ), Row Table( Grouping Columns( :Name ) ) ) )) << Make Into Data Table
@uday_guntupalli What if one of the columns I have has character data type?
@Aam_jmp, I would think Tabulate can still work. If you had a new column "Test" and Tabulated you would end up with something like this :
dt = Current Data Table(); dt1 = (dt << Tabulate( Set Format( N( 9, "Best" ) ), Add Table( Column Table( Analysis Columns( :Age, :Height, :Weight ) ), Column Table( Grouping Columns( :Test ) ), Row Table( Grouping Columns( :Name ) ) ) )) << Make Into Data Table
If this doesn't address what you are asking, kindly show what your data looks like (like a sample) - so I can see where I am off.
@uday_guntupalli I have already tried doing this. This seems to make a new column for every value that is present in the column. I would like to know if there is any option in JMP that would help me acquire something like this: