Subscribe Bookmark RSS Feed

Reference Data Tables in a Loop to Create Distributions

sophiaw

Community Trekker

Joined:

Jul 10, 2015

1 ACCEPTED SOLUTION

Accepted Solutions
ms

Super User

Joined:

Jun 23, 2011

Solution

If dtPinGroups is a list of variables I think Eval() is needed:

        Eval(dtPinGroups[i]) << Distribution( Column(:Leakage_Data));


If you have a list of current table names (as strings) this should also work:

        Data Table(dtPinGroupNames[i]) << Distribution( Column(:Leakage_Data));

To build commands as a string – like in PMroz' example – is great to have in your tool box, especially when more straightforward methods refuse to work. But I usually try a direct method first, simply because I find it easier to code (and to read). The former of the approaches above applied to PMroz' example would be:

dt1 = Open("$sample_data/Big Class.jmp");

dt2 = Open("$sample_data/Animals.jmp");

dt3 = Open("$sample_data/Analgesics.jmp");

dtpingroups = {dt1, dt2, dt3};

dtpingroupnames = {"Big Class", "Animals", "Analgesics"};

var_list = {:height, :miles, :pain};

wind = {};

For(i = 1, i <= N Items(dtpingroups), i++,

    wind[i] = New Window("Leakage_" || dtpingroupnames[i] || "_Distribution",

        Eval(dtpingroups[i]) << Distribution(Continuous Distribution(Column(var_list[i])))

    )

);

4 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

Try an approach like this:

dt1 = open("$sample_data/Big Class.jmp");

dt2 = open("$sample_data/Animals.jmp");

dt3 = open("$sample_data/Analgesics.jmp");

dtpingroups = {dt1, dt2, dt3};

dtpingroupnames = {"Big Class", "Animals", "Analgesics"};

var_list        = {:height, :miles, :pain};

wind = {};

for (i = 1, i <= nitems(dtpingroups), i++,

       one_expr = evalinsert(

"\[    wind = new window("Leakage ^dtpingroupnames^_Distribution",

              ^dtpingroups^ << Distribution( Continuous Distribution( Column(^var_list^ ) ) )

       );]\");

       eval(parse(one_expr));

);

I had to build the commands dynamically as a string and then execute them with eval(parse()).

sophiaw

Community Trekker

Joined:

Jul 10, 2015

Thank you! That worked perfectly!

ms

Super User

Joined:

Jun 23, 2011

Solution

If dtPinGroups is a list of variables I think Eval() is needed:

        Eval(dtPinGroups[i]) << Distribution( Column(:Leakage_Data));


If you have a list of current table names (as strings) this should also work:

        Data Table(dtPinGroupNames[i]) << Distribution( Column(:Leakage_Data));

To build commands as a string – like in PMroz' example – is great to have in your tool box, especially when more straightforward methods refuse to work. But I usually try a direct method first, simply because I find it easier to code (and to read). The former of the approaches above applied to PMroz' example would be:

dt1 = Open("$sample_data/Big Class.jmp");

dt2 = Open("$sample_data/Animals.jmp");

dt3 = Open("$sample_data/Analgesics.jmp");

dtpingroups = {dt1, dt2, dt3};

dtpingroupnames = {"Big Class", "Animals", "Analgesics"};

var_list = {:height, :miles, :pain};

wind = {};

For(i = 1, i <= N Items(dtpingroups), i++,

    wind[i] = New Window("Leakage_" || dtpingroupnames[i] || "_Distribution",

        Eval(dtpingroups[i]) << Distribution(Continuous Distribution(Column(var_list[i])))

    )

);

sophiaw

Community Trekker

Joined:

Jul 10, 2015

That also worked perfectly! (and it is much easier for me to understand what is going on!) Thank you!!