
好的。因此,僅在查看所選區域時。我想要:
Nback#= 1,持續時間= 14303912,累積持續時間= 0
Nback#= 2 ,duration = 14305914,累積持續時間= 2002
Nback#= 3 ,duration = 14307916,累積持續時間= 4004
Nback#= 4 ,duration = 14309965,累積持續時間= 6053
Nback#= 5 ,duration = 14312015,累積持續時間= 8103
Nback#= 6 ,duration = 14314051,累積持續時間= 10139
我需要將這個最後一欄作為時間的衡量標準。任何指導將不勝感激。
因此,進行這一小改動仍會為我的新變量產生相同類型的輸出。
您可以總結持續時間,但可能會錯過行之間的時間。在我看來,使用開始和結束時間(Nback Start和Nback Stop以及summary_image_end)相當簡潔。 該公式應該如下所示。 您可以使用*或者*藍色列(如果您關心summary_image_end)或紅色列(如果您關心Lag1)。

所以在查看我的數據時,我意識到我有一個'Nback Duration'列。我想知道是否有更簡單的方法來使用此列和lag1列獲得所需的最終結果。
這是一種只使用列公式執行此操作的方法。 我不確定您使用哪個列來指示時間重置,所以我包括在內
- 一種方法,可以從每個新組的值更改的列中執行此操作
- 一種基於列的方法,指示時間重置。
Names default to here ( 1 );
//Table with data similar to yours
dt = New Table( "Data",
Add Rows( 40 ),
New Column( "Space", Numeric, "Continuous",
Format( "Best", 12 ),
Formula( Round( Random Uniform( 1, 5 ), 0 ) )
),
New Column( "Duration", Numeric, "Continuous",
Format( "Best", 12 ),
Formula( Round( Random Uniform( 1998, 2002 ), 0 ) )
),
New Column( "Start", Numeric, "Continuous",
Format( "Best", 12 ),
Formula( If( Row() == 1, :Space, :Space + Lag( :Start, 1 ) + Lag( :Duration, 1 ) ) )
),
New Column( "End", Numeric, "Continuous",
Format( "Best", 12 ),
Formula( :Start + :Duration )
),
New Column( "Period Indication", Character, "Nominal",
Formula( If( Row() < 15, "One", "Two" ) )
),
New Column( "Indication of Time Reset Pulse", Numeric, "Nominal",
Formula( If( Row() == 10, 1, . ) )
)
);
//New Column - subtract the current end time from the first end time in
//the group. Use this if the column :summary_image_end" tells you when
//to start a new group
dt << New Column( "Time In Group", Numeric, "Continuous",
Format( "Best", 12 ),
Formula( :End - Col Min( :Start, :Period Indication ) )
);
//Make a New Column indicating the period for a pulse signal, use this if
//the column Lag1 tells you when to start a new group
dt << New Column( "Period Indication from Pulse", Numeric, "Nominal",
Format( "Best", 12 ),
Formula(
If(
Row() == 1,
1,
Lag( :Period Indication from Pulse, 1 ) +
If(
Is Missing( :Indication of Time Reset Pulse ),
0,
1
)
)
)
);
//Once the group column is made then calculate the duration
dt << New Column( "Time In Group - Pulse", Numeric, "Continuous",
Format( "Best", 12 ),
Formula( :End - Col Min( :Start, :Period Indication from Pulse ) )
);這個腳本可能就是您所需要的。數據設置為附件。
dt = Current Data Table();
//dt << New Column( "Delta", numeric );
dt << New Column( "Cumulative", numeric );
dt << Sort( By( :Category, :Time ), Order( Ascending, Ascending ), Replace table );
For( i = 1, i <= N Rows( dt ), i++,
If( :Time[i] == Min( :Time[dt << get rows where( :Category == :Category[i] )] ),
//dt:Delta[i] = 0;
dt:Cumulative[i] = 0;
,
//dt:Delta[i] = dt:Time[i] - dt:Time[i - 1];
dt:Cumulative[i] = dt:Cumulative[i-1]+ (dt:Time[i] - dt:Time[i - 1]);
)
);