我對同一零件號碼的原始資料進行了多次測量。我怎麼才能獲得一列中的最後一個條目。

這可能有效:
// 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];