简体   繁体   English

在 for 循环中,如果用户在 R 中的时间戳之前和之后都没有数据,则移动到下一个循环

[英]In a for loop, moving to next loop if a user doesn't have data both before and after a timestamp in R

I have written a loop that works but is super slow because it iterates through users that don't have both pre- and post- data in an intervention study.我编写了一个有效的循环,但速度非常慢,因为它遍历在干预研究中没有前后数据的用户。 For my purposes, I would only like to include users who have data before and after a certain timestamp (of which the timestamp is different for each user).出于我的目的,我只想包括在某个时间戳之前和之后拥有数据的用户(每个用户的时间戳不同)。

Essentially, I would like a loop that says:本质上,我想要一个循环,它说:

if (user_file$date does not have values BOTH before AND after user_file$timestamp) {
      next
    }

Many thanks in advance for any assistance.非常感谢您提供任何帮助。

You'll want to do some preprocessing of your data: For each user compute their earliest and latest data entry dates.您需要对数据进行一些预处理:为每个用户计算他们最早和最晚的数据输入日期。 Then in your loop, you can just check if the user's earliest date is before their corresponding timestamp and if their latest date is after their corresponding timestamp.然后在您的循环中,您可以检查用户的最早日期是否在其相应的时间戳之前,以及他们的最新日期是否在其相应的时间戳之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM