
好的。因此,仅在查看所选区域时。我想要:
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]);
)
);