How do I condition a for loop to work only for a particular set of rowsHi,
I'm trying to manipulate a data table with a formula, but I only want it to read for a few rows.
Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Cars.jmp" );
r = Current Data Table() << Get rows where( :Make == "Mazda");
For( i = r[1], i <= r, i++,
:HeadIC[i] = :HeadIC[i]/2
);
Show(r);
How do I make it so that it only iterates for those selected rows?
Consumer and Market ResearchMass CustomizationRe: How do I condition a for loop to work only for a particular set of rowsLike this?
Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Cars.jmp" );
For Each Row( If ( :Make == "Mazda", :HeadIC = :HeadIC/2 ));
Re: How do I condition a for loop to work only for a particular set of rowsIn your example, since you have made the vector with the row numbers, you can also use "For Each()". This would be faster, especially for a larger data table (with may rows).
Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Cars.jmp" );
r = Current Data Table() << Get rows where( :Make == "Mazda");
for each({cr,ii}, r,
:headic[cr] = :headic[cr]/2
);
Re: How do I condition a for loop to work only for a particular set of rowsPlease demystify this for me:
for each({cr,ii}, r,
:headic[cr] = :headic[cr]/2
);
// specifically, where do {cr,ii} come from and what do they do?
Not a coder. Couldn't find this in the Scripting Index. Haven't checked the Scripting Guide yet.
Re: How do I condition a for loop to work only for a particular set of rowsHi, I'm unsure how to use that function, I cant find it in the scripting index, can you show an example? When I try to run the code that you gave, errors pop up.
Re: How do I condition a for loop to work only for a particular set of rowsFor Each() is new function introduced in JMP16, so if you are using older version of JMP you won't find it in scripting index (and it will give an error). You could convert it to for-loop if you wanted to:
Names Default To Here( 1 );
Open( "$SAMPLE_DATA/Cars.jmp" );
r = Current Data Table() << Get rows where( :Make == "Mazda");
/*For Each({cr,ii}, r,
:headic[cr] = :headic[cr]/2
);*/
For(ii = 1, ii <= N Items(r), ii++,
cr = r[ii];
:headic[cr] = :headic[cr]/2;
);
For Each(names, container, locals, body) (jmp16 help)
Re: How do I condition a for loop to work only for a particular set of rowsThat's strange. Both work just fine for me. Try again posting the full code of each solution into a separate script window. Close everything else. Run first the code from one script window, confirming that the code does what it is supposed to do. Then, close everything again apart from the other script window containing the code you still need to test.