원시에서 동일한 부품 번호에 대한 여러 측정값이 있습니다. 한 열에서 마지막 항목을 가져오려면 어떻게 해야 합니까?

이렇게 하면 효과가 있을 수 있습니다:
// make a column to hold results, it will be last column
dt << newcolumn("answer");
for(irow=1,irow<=nrows(dt),irow+=1,
// assumes columns 1 and 2 and last are NOT data...
// grab one row at a time...
vec = dt[irow, 3::(ncols(dt)-1)];
// get indexes (loc) of non-missing values...pick the right-most (max)
nonmissindex = max(loc(vec));
// handle possible edge case (no data)
value = if(ismissing(nonmissindex),.,vec[nonmissindex]);
// fill in the answers
dt:answer[irow] = value;
);
이를 열 수식으로 바꾸는 경우 테이블 업데이트를 위해 소스 열을 명시적으로 나열해야 하며 dt는 필요하지 않습니다.
dt << New Column( "answer",
formula(
vec = run_1 || run_2 || run_3 || run_4;
nonmissindex = Max( Loc( vec ) );
If( Is Missing( nonmissindex ),
. // missing if all missing
, //
vec[nonmissindex]
);
)
);
수식의 경우 데이터가 변경되면 답변 열이 업데이트됩니다.
내가 생각해 낸 공식은 다음과 같습니다.
dt = Current Data Table();
x = Row();
col = Length( Loc( dt[x, Index( 3, 6 )] ) ) + 2;
dt[x, col];