Creating a week day field

I am trying to create a weekday field using the wday function. The sponsor of this project gave us the following code:

analyze ridership data by type and weekday

all_trips_v2 %>%
mutate(weekday = wday(started_at, label = TRUE)) %>% #creates weekday field using wday()
group_by(member_casual, weekday) %>% #groups by usertype and weekday
summarise(number_of_rides = n() #calculates the number of rides and average duration
,average_duration = mean(ride_length)) %>% # calculates the average duration
arrange(member_casual, weekday) # sorts

I keep getting an error stating that (could not find function "wday")
Can somebody please help by telling me what am I doing wrong?
Thanks in advance.
Jesus

Hi @Jesus_Prato , you activate library(lubridate)?

library(dplyr)
library(lubridate)

sales_data <- data.frame(
  Date = seq(as.Date("2022-01-01"), as.Date("2022-01-31"), by = "day"),
  Sales = runif(31, 100, 1000))


sales_by_wday <- sales_data %>%
  dplyr::mutate(wday = wday(Date, label = TRUE)) %>%
  group_by(wday) %>%
  summarise(total_sales = sum(Sales))


ggplot(sales_by_wday, aes(x = wday, y = total_sales)) +
  geom_bar(stat = "identity") +
  labs(x = "Day of the Week", y = "Total Sales", title = "Sales by Day of the Week")

wday() is part of the lubridate package. Have you run

library(lubridate)