스크립트로 여러 열 추가여보세요,
정의된 데이터 테이블에 여러 열을 추가하는 것이 궁금합니다. 열이 이미 존재하는 경우 스크립트는 열을 무시하고 구현될 때까지 존재하지 않으면 나머지 열을 계속 추가할 수 있습니다.
여기에 스크립트를 작성했습니다. 그러나 문제는 열이 존재하더라도 스크립트는 여전히 데이터 테이블에 중복 열을 추가한다는 것입니다. 이 문제를 해결하는 데 도움을 줄 수 있습니까? 감사합니다!
Names Default To Here( 1 );
dt0 = Current Data Table();
tnames = dt0 << Get Column Names;
n = N Items( tnames );
For( i = 1, i <= n, i++,
If( (tnames[i] == Char("CpK<1.0") ),
judA = 0,
judA=1
);
If( (tnames[i] == Char("1.0<=CpK <1.33") ),
judB = 0,
judA=1
);
If( (tnames[i] == Char("1.33<=CpK<1.67") ),
judC = 0,
judC=1
);
If( (tnames[i] == Char("1.67<=CpK<2.0") ),
judD = 0,
judD=1
);
If( (tnames[i] == Char("CpK>=2.0") ),
judE = 0,
judE=1
);
);
If( judA == 1,
dt0 << New Column( "CpK<1.0", numeric, formula( If( :Cpk < 1, 1, 0 ) ), EvalFormula ),
);
If( judB == 1,
dt0 << New Column( "1.0<=CpK <1.33", numeric, formula( If( 1 <= :Cpk < 1.33, 1, 0 ) ), EvalFormula ),
);
If( judC == 1,
dt0 << New Column( "1.33<=CpK<1.67", numeric, formula( If( 1.33 <= :Cpk < 1.67, 1, 0 ) ), EvalFormula ),
);
If( judD == 1,
dt0 << New Column( "1.67<=CpK<2.0", numeric, formula( If( 1.67 <= :Cpk < 2, 1, 0 ) ), EvalFormula ),
);
If( judE == 1,
dt0 << New Column( "CpK>=2.0", numeric, formula( If( :Cpk >= 2, 1, 0 ) ), EvalFormula ),
);Re: 스크립트로 여러 열 추가정말 고마워요, 빈스!효과가있다.
Re: 스크립트로 여러 열 추가이런 식으로 할 수 있습니다.
Names default to here(1);
dt = open("$SAMPLE_DATA\Big Class.jmp");
dt << New Column("Cpk", Set Each Value(random normal(1, 1)));
dt << New Column("1.0<=CpK <1.33", Set Each Value(0));
col_names = dt << Get column names(string); // this is your existing columns
//I would just do a not contains which checks where an item is in a list, returning 0 if it doesn't
if(!Contains(col_names, "CpK<1.0"),
dt << New Column( "CpK<1.0", numeric,
formula(
// you also don't have to do the if(thing, 1, 0) :Cpk < 1 will resolve to 1 and 0 anyway
:Cpk < 1
)
)
);
// this one shouldn't get remade
if(!Contains(col_names, "1.0<=CpK <1.33"),
dt << New Column( "1.0<=CpK <1.33", numeric, formula( 1.0<=:Cpk <1.33 ))
);
if(!Contains(col_names, "1.33<=CpK<1.67"),
dt << New Column( "1.33<=CpK<1.67", numeric, formula( 1.33<=:Cpk <1.67 ))
);
if(!Contains(col_names, "1.67<=CpK<2.0"),
dt << New Column( "1.67<=CpK<2.0", numeric, formula( 1.67<=:Cpk <2 ))
);
if(!Contains(col_names, "CpK>=2.0"),
dt << New Column( "CpK>=2.0", numeric, formula( 2.0<=:Cpk ))
);
또한 데이터 구조를 1개만 변경할 수 있도록 약간 추상화할 수 있으며 필드가 변경됩니다.
//But I would probably do it another way
Names default to here(1);
dt = open("$SAMPLE_DATA\Big Class.jmp");
dt << New Column("Cpk", Set Each Value(random normal(1, 1)));
dt << New Column("1<=Cpk<1.33", Set Each Value(0));
col_names = dt << Get column names(string); // this is your existing columns
//I'd make a 2 col matrix with low and high check then make the columns dynamically
cpk_check = [. 1, 1 1.33, 1.33 1.67, 1.67 2, 2 .];
for(i=1, i<=nrows(cpk_check), i++,
low = cpk_check[i, 1];
high = cpk_check[i, 2];
if(!ismissing(low),
if(!ismissing(high),
col_name = char(low) || "<=Cpk<" ||char(high);
f = EvalExpr(Expr(low)<=:Cpk<EXPR></EXPR>
Re: 스크립트로 여러 열 추가감사합니다 티에리! 그렇다면 이 문제를 어떻게 해결해야 할까요?Re: 스크립트로 여러 열 추가안녕,
문제는 5개의 스위치 judA - judE가 각 열에 대해 재평가되는 루프에 있습니다. 따라서 n개의 기존 열을 살펴보고 나면 모든 스위치의 상태가 마지막 열로 설정됩니다.