0

I have a dataframe with a column TimeStamp. I'm able to filter the dataframe based on a date range. I want to further filter it by hour of the day as well, i.e. lets say 8 AM to 11 am in morning and 5pm to 9pm in evening. How can both be combined. I can further filter based on hour of day, I suppose, but how to combine both? Sample data is

    head(psknk_all_filtered_evening)
    | ID_frame     |      TimeStamp   |            MAC| RSSI  |                                       
    |Vendor |        cod| sync|
|:.......|:...........|:...........|:........
|1  | 129915| 2021-02-25 18:54:51 |00:13:43:70:96:6A | -83 |Matsushita Electronic Components (Europe) GmbH|    Wearable |   1|
2   129916 2021-02-25 18:54:51 20:65:E9:51:0C:00  -87                                        Unknown     A/V Car    1
3   129917 2021-02-25 18:54:51 35:6F:74:D1:0D:9A  -88                                        Unknown A/V Headset    1
4   129918 2021-02-25 18:54:51 48:83:B4:E1:12:74  -85                                        Unknown  SmartPhone    1
5   129919 2021-02-25 18:54:51 70:5E:55:E9:25:EE  -83                                        Unknown  SmartPhone    1
6   129920 2021-02-25 18:54:51 70:DD:A8:09:7D:5A  -90                                        Unknown  SmartPhone    1

    |MeshliumID|

|1 |1.914211e+13|
2 1.914211e+13
3 1.914211e+13
4 1.914211e+13
5 1.914211e+13
6 1.914211e+13
  • 1
    Welcome to SO! It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including the code you tried, the packages you used and a snippet of your data or some fake data. – stefan Mar 19 '22 at 10:31
  • 1
    It would be helpful if you provide sample dataset using `dput(x)` – Nad Pat Mar 19 '22 at 10:32
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 21 '22 at 15:36

1 Answers1

0

I could manage to do the filtering using dplyr and lubridate package and following command to the dataframe thru pipe operator.

%>%
filter(TimeStamp >= as.Date('2021-02-25') & TimeStamp <= as.Date('2021-03-09'), hour(TimeStamp) >= 17 & hour(TimeStamp)  <= 22)
%>%

hour(TimeStamp) >= 17 & hour(TimeStamp) <= 22 was the key to filter using lubridate package.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 21 '22 at 12:08