0

So I'm trying to filter out the date and time for individual fish within my data frame. In the code below line 19 by itself will filter the dataframe to give me the times for that ID within the parameters I set but when I add line 20 everything gets filtered out and the data frame is empty.

I assume I'm linking the lines incorrectly but I'm not sure how else it should be done.

ev4<-ev %>% 
  filter(ID<46|ID>135) %>% 
  filter(ID!=166) %>% #Take everything but not 166
  filter(d<25) %>% 
  filter(Receiver=="1315"|
           Receiver=="1314"|
           Receiver=="1321"|
           Receiver=="1404"|
           Receiver=="1318"|
           Receiver=="1325"|
           Receiver=="1313"|
           Receiver=="1323"|
           Receiver=="1324"|
           Receiver=="1320"|
           Receiver=="1319"|
           Receiver=="1317"|
           Receiver=="1327"|
           Receiver=="1316") %>% 
  filter(ID == "1", dt <= as.POSIXct("2020-05-23 03:20:36"), dt >= as.POSIXct("2020-05-07 23:50:12")|
  ID=="3",dt <= as.POSIXct("2020-05-03 16:13:00")) %>% 
  filter() %>% 
  mutate(sp=case_when(ID<46~"salmon", T~"trout")) %>% 
  mutate(dt=ymd_hms(dt)) %>% 
  as_tibble()

For example if my dataframe was like: enter image description here

I might want to filter the dataframe so it only contained the dates for ID 138 between "2020-04-23 19:26:47" and 2020-04-23 19:26:56. But I would also want to be able to keep the rest of the data frame intact.

Student121
  • 15
  • 4
  • Provide example input data and expected output. Read about `%in%` operator. Also, you can use only one `filter` and keep all conditions in it. – zx8754 Mar 03 '21 at 08:03
  • I'm not sure what you mean by the input and output data, would that not be "date time" I specified within the filtering? The rest of the code filters out everything perfectly, it's just now I'm trying to specify within certain date time ranges for each specific "ID" – Student121 Mar 03 '21 at 08:16
  • 1
    https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – zx8754 Mar 03 '21 at 08:17

1 Answers1

0

Realised I was going the long way about it. Filtered each ID into separate data frames and then joined them together with full_join(x, y)

Student121
  • 15
  • 4