创建第a行上的end_time变量,从start_time变量在行B上创建
我想根据每个参与者的start_times和time_end_of_experiment(减去10毫秒)为每个参与者创建一个end_time变量,但完全不确定该怎么做。
这是一个最小的工作示例
df <- data.frame("subject_nr" = c("1", "1", "1", "2", "2"),
"start_time" = c(50, 52, 55, 53, 54.5),
"time_end_of_experiment" = c(60, 60, 60, 55.5, 55.5))
subject_nr start_time time_end_of_experiment
1 1 50.0 60.0
2 1 52.0 60.0
3 1 55.0 60.0
4 2 53.0 55.5
5 2 54.5 55.5
,这是最终产品的外观
subject_nr start_time end_time time_end_of_experiment
1 1 50.0 51.9 60
2 1 52.0 54.9 60
3 1 55.0 59.9 60
4 2 53.0 54.4 55.5
5 2 54.5 55.4 55.5
I would like to create an end_time variable for each participant based on their start_times and time_end_of_experiment (minus say 10 ms), but quite unsure how to do this.
Here's a minimal working example
df <- data.frame("subject_nr" = c("1", "1", "1", "2", "2"),
"start_time" = c(50, 52, 55, 53, 54.5),
"time_end_of_experiment" = c(60, 60, 60, 55.5, 55.5))
subject_nr start_time time_end_of_experiment
1 1 50.0 60.0
2 1 52.0 60.0
3 1 55.0 60.0
4 2 53.0 55.5
5 2 54.5 55.5
Here's what the final product should look like
subject_nr start_time end_time time_end_of_experiment
1 1 50.0 51.9 60
2 1 52.0 54.9 60
3 1 55.0 59.9 60
4 2 53.0 54.4 55.5
5 2 54.5 55.4 55.5
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我们可以做到的:
首次使用
LEAD
从Lead(start_time)
提取0.1然后,对于组中的最后一个值,请使用ifelse语句从time_end_of_experiment提取0.1:
Here is how we could do it:
First use
lead
to substract 0.1 fromlead(start_time)
then for the last value in the groups use an ifelse statement to substract 0.1 from time_end_of_experiment: