0

I am having some trouble trying to remove various rows of a data frame in R based on the results of some previous code.

This is the head and tail of the "big" data frame that I am trying to subset.

subj                           time_utc            time_cst axis1 axis2 axis3 steps       date
1       SKPD_PD_001 2017-11-16 17:02:00 2017-11-16 11:02:00    81    22    35     1 2017-11-16
2       SKPD_PD_001 2017-11-16 17:03:00 2017-11-16 11:03:00   509   355   336     4 2017-11-16
3       SKPD_PD_001 2017-11-16 17:04:00 2017-11-16 11:04:00     0     0     0     0 2017-11-16
4       SKPD_PD_001 2017-11-16 17:05:00 2017-11-16 11:05:00    88     3     6     1 2017-11-16
5       SKPD_PD_001 2017-11-16 17:06:00 2017-11-16 11:06:00     0     0     0     0 2017-11-16
6       SKPD_PD_001 2017-11-16 17:07:00 2017-11-16 11:07:00     0     0     0     0 2017-11-16
1324477 SKPD_PD_032 2018-09-28 18:35:00 2018-09-28 13:35:00   884   463  2998    13 2018-09-28
1324478 SKPD_PD_032 2018-09-28 18:36:00 2018-09-28 13:36:00   464    63  1957     8 2018-09-28
1324479 SKPD_PD_032 2018-09-28 18:37:00 2018-09-28 13:37:00   224   728   885     5 2018-09-28
1324480 SKPD_PD_032 2018-09-28 18:38:00 2018-09-28 13:38:00   190    53   322     3 2018-09-28
1324481 SKPD_PD_032 2018-09-28 18:39:00 2018-09-28 13:39:00   108    93  1168     4 2018-09-28
1324482 SKPD_PD_032 2018-09-28 18:40:00 2018-09-28 13:40:00   624  1058  1288     8 2018-09-28

I need to remove all rows of specific dates for each subject that need to be eliminated from analysis. This is the head of the dataframe that contains the subject ID and date(s) that subject should not have in analysis.

         subj       date
1 SKPD_PD_001 2017-11-16
2 SKPD_PD_002 2017-11-29
3 SKPD_PD_002 2017-12-28
4 SKPD_PD_002 2018-01-02
5 SKPD_PD_003 2017-11-30
6 SKPD_PD_003 2017-12-01

Basically, I want all of the rows of subject 1's data from 11/16, subject 2's data from 11/29, 12/28, and 1/2, etc. to be removed from the overall dataframe. One trouble is that multiple subjects have data from each date.

I've tried a couple different for loops but I can't seem to find a good solution that allows me to limit by subject and by date. Below is one attempt that I tried to get the index of the rows so I could then do act.all[-d] to remove all of the rows with those indices, but it did not work for me.

d <- 0

for (subject in act.all$subj) {
  if(subject == removedays$subj && removedays$date == act.all$date) {
    d <- c(d,index(subject))
  }
}

Any help would be greatly appreciated!

res3arc
  • 1
  • 1

0 Answers0