Is it possible to select only weekends or weekdays?

I'm doing a project where I want to compare the activity patterns of deer, and the difference between weekends and weekdays to see if there is a change.

I'm very new to R, I've been using it for less than a month just for this class.
I have over 1000+ observations over 3 years in my data set right now so I can't sort them by hand

What can I do to separate the dates that fall on weekdays from the weekends?

I'm not sure what information is necessary but I'm using Rmarkdown and the packages tidyverse, lubridate, circular, and overlap

library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union
my_data <- data.frame(Date = seq(as.Date("2000/1/1"), by = "day", length.out = 1000), census = sample(1:100,1000,replace = TRUE))
weekend <- c(1,7) # Weeks start on Sunday and end on Saturdayt
weekday <- 2:6
my_weekends <- my_data[which(wday(my_data$Date) %in% weekend),]
head(my_weekends)
#>          Date census
#> 1  2000-01-01     10
#> 2  2000-01-02     28
#> 8  2000-01-08     35
#> 9  2000-01-09     33
#> 15 2000-01-15     42
#> 16 2000-01-16     35
my_weekdays <- my_data[which(wday(my_data$Date) %in% weekday),]
head(my_weekdays)
#>          Date census
#> 3  2000-01-03     67
#> 4  2000-01-04     58
#> 5  2000-01-05     88
#> 6  2000-01-06     38
#> 7  2000-01-07     68
#> 10 2000-01-10     22

Created on 2022-12-07 by the reprex package (v2.0.1)

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.