0
all_trips2 %>%
        mutate(weekday = wday(started_at, label = TRUE)) %>%
        group_by(member_casual, weekday) %>% 
        summarise(number_of_rides = n(),average_duration = mean(ride_length))


 dput(head(all_trips2))
structure(list(ride_id = c("21742443", "21742444", "21742445", 
"21742446", "21742447", "21742448"), started_at = c("1/1/19 12:04 AM", 
"1/1/19 12:08 AM", "1/1/19 12:13 AM", "1/1/19 12:13 AM", "1/1/19 12:14 AM", 
"1/1/19 12:15 AM"), ended_at = c("1/1/19 12:11 AM", "1/1/19 12:15 AM", 
"1/1/19 12:27 AM", "1/1/19 12:43 AM", "1/1/19 12:20 AM", "1/1/19 12:19 AM"
), rideable_type = c("2167", "4386", "1524", "252", "1170", "2437"
), ride_length = c(390, 441, 829, 1783, 364, 216), start_station_id = c(199, 
44, 15, 123, 173, 98), start_station_name = c("Wabash Ave & Grand Ave", 
"State St & Randolph St", "Racine Ave & 18th St", "California Ave & Milwaukee Ave", 
"Mies van der Rohe Way & Chicago Ave", "LaSalle St & Washington St"
), end_station_id = c(84, 624, 644, 176, 35, 49), end_station_name = c("Milwaukee Ave & Grand Ave", 
"Dearborn St & Van Buren St (*)", "Western Ave & Fillmore St (*)", 
"Clark St & Elm St", "Streeter Dr & Grand Ave", "Dearborn St & Monroe St"
), member_casual = c("member", "member", "member", "member", 
"member", "member"), date = structure(c(-719144, -719144, -719144, 
-719144, -719144, -719144), class = "Date"), month = c("01", 
"01", "01", "01", "01", "01"), day = c("19", "19", "19", "19", 
"19", "19"), year = c("0001", "0001", "0001", "0001", "0001", 
"0001"), day_of_week = structure(c(6L, 6L, 6L, 6L, 6L, 6L), .Label = c("Sunday", 
"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
), class = c("ordered", "factor"))), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"))

I keep getting this code error and cannot figure out what I'm doing wrong. This is from a provided exercise script for the Google Data Analytics case study.

Sean
  • 1
  • 1
  • Hi Sean, it is very difficult to answer such a question if we cannot see your data. Could you maybe share part of your data using `dput()`? I assume the column `started_at` is a character column which is not always in a nice date format. – Bas Aug 23 '22 at 06:50
  • @Bas The dataset has over 3.1 million rows is that too much to send on here? – Sean Aug 24 '22 at 03:34
  • Yes, that is too much. You can just share the first couple of rows using for example `head()`. With just code we cannot help you, we need to see the data as well. If you cannot share your own data, you can try to create an example data set that looks like your original data. Check out https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example. – Bas Aug 24 '22 at 08:36
  • 1
    Welcome on SO! Include the packages you used at the top of your code, i.e. `library(tidyverse);library(lubridate)`. And I get no errror running this code. Maybe this is because you shared just a part of the data (`head()`), which would mean that the error is beacuse of some other entries in your data. – LulY Aug 24 '22 at 09:45
  • Is there anywhere that I can share the Excel data sheets and have anyone take a look? I just changed the column into M/D/YYYY format, but I'm still coming up with the same code. Please let me know – Sean Aug 25 '22 at 03:59
  • 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 Aug 30 '22 at 23:09

1 Answers1

0

This problem has been fixed. The problem was that the Date was a character vector instead of a date vector. So I switched it using the code below:

all_trips2$date <- as.Date(all_trips2$started_at)
blackraven
  • 5,284
  • 7
  • 19
  • 45
Sean
  • 1
  • 1