A case study: Cyclistic Bike-Share Analysis

Image by pch.vector on Freepik
Image by pch.vector on Freepik

INTRODUCTION

Source: Case study background was provided by Google Data Analytics

The Company In 2016, Cyclistic launched a successful bike-sharing offering. Since then, the program has grown to a fleet of 5,824 bicycles that are geotracked and locked into a network of 692 stations across Chicago. The bikes can be unlocked from one station and returned to any other station in the system at anytime.

Cyclistic: A bike-share program that features more than 5,800 bicycles and 600 docking stations. Cyclistics sets itself apart by also offering reclining bikes, hand tricycles, and cargo bikes, making bike-share more inclusive to people with disabilities and riders who can’t use a standard two-wheeled bike. The majority of riders opt for traditional bikes; about 8% of riders use the assistive options. Cyclistic users are more likely to ride for leisure, but about 30% use them to commute to work each day.

Cyclistic Marketing Analytic Team (CMAT): A team of data analysts for collecting, analyzing, and reporting data that helps guide Cyclistic marketing strategy.

Lily Moreno: The director of marketing and the manager of CMAT. Ms. Moreno is responsible for the development of campaigns and initaitves to promote the bike-sharing program.

Cyclistic Executive Team: The notoriously detail-oriented executive team will decide whether to approve the recommended marketing program.

Cyclistic’s finance analysts have concluded that annual members are much more profitable than casual riders. Although the pricing flexibility helps Cyclistic attract more customers, Ms. Moreno believes the company’s future success depends on maximizing the number of annual memberships. She believes there is a very good chance to convert causal riders into members. Therefore, CMAT wants to understand how casual riders and annual members use Cyclistic bikes differently. From these insights, the CMAT will design a new marketing strategy to convert casual riders into annual members by following these steps:

Case Study Methodology

  1. Ask Phase: Clear statement of the business task
  2. Prepare Phase: Description of all data sources used
  3. Process Phase: Documentation of any cleaning or manipulation of data
  4. Analyze Phase: Summary of analysis
  5. Share Phase: Visualizations and key findings
  6. Act Phase: Top three recommendations

1. ASK

Problem statement

Ms. Morenao has assigned you the first question to answer: How do annual members and casual riders use Cyclistic bikes differently?

Based on results finding, you are to provide a top three recommendations.

Stakeholders:

2. PREPARE

Data source

The analysis was conducted in RStudio due to the capability of data cleaning, data manipulation, visualization, and presentation.

All data is collected from real world company called Motivate International Inc. The data is publically available here under this license. A total of 11 datasets (CSV files), each for every month of the year 2023 (Jan 2023 to Nov 2023) will be used to perform this case study.

202301-divvy-tripdata.csv, 202302-divvy-tripdata.csv, 202303-divvy-tripdata.csv, 202304-divvy-tripdata.csv, 202305-divvy-tripdata.csv, 202306-divvy-tripdata.csv, 202307-divvy-tripdata.csv, 202308-divvy-tripdata.csv, 202309-divvy-tripdata.csv, 202310-divvy-tripdata.csv, 202311-divvy.tripdata.csv

Each dataset includes the following column names: ride_id, rideable_type, started_at, ended_at, start_station_name, start_station_id, end_station_name, end_station_id, start_lat, start_lng, end_lat, end_lng, member_casual.

The data is reliable and vetted by the Google Data Analytics team for the purpose of case study. The data meets the criteria for ROCCC:

Set up the environment and install all relevant packages in RStudio.

#install packages
library(tidyverse) #helps wrangle data
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate) #helps wrangle date attributes
library(janitor) #helps clean data 
## 
## Attaching package: 'janitor'
## 
## The following objects are masked from 'package:stats':
## 
##     chisq.test, fisher.test
library(ggplot2) #helps visualize data
library(readr) #helps read rectangular data from delimited files

Collect data. Upload Divvy datasets(csv files).

#upload Divvy datasets (jan-nov)
jan_2023<-read_csv("202301-divvy-tripdata.csv")
## Rows: 190301 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (7): ride_id, rideable_type, start_station_name, start_station_id, end_...
## dbl  (4): start_lat, start_lng, end_lat, end_lng
## dttm (2): started_at, ended_at
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
feb_2023<-read_csv("202302-divvy-tripdata.csv")
## Rows: 190445 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (7): ride_id, rideable_type, start_station_name, start_station_id, end_...
## dbl  (4): start_lat, start_lng, end_lat, end_lng
## dttm (2): started_at, ended_at
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
mar_2023<-read_csv("202303-divvy-tripdata.csv")
## Rows: 258678 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (7): ride_id, rideable_type, start_station_name, start_station_id, end_...
## dbl  (4): start_lat, start_lng, end_lat, end_lng
## dttm (2): started_at, ended_at
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
apr_2023<-read_csv("202304-divvy-tripdata.csv")
## Rows: 426590 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (7): ride_id, rideable_type, start_station_name, start_station_id, end_...
## dbl  (4): start_lat, start_lng, end_lat, end_lng
## dttm (2): started_at, ended_at
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
may_2023<-read_csv("202305-divvy-tripdata.csv")
## Rows: 604827 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (7): ride_id, rideable_type, start_station_name, start_station_id, end_...
## dbl  (4): start_lat, start_lng, end_lat, end_lng
## dttm (2): started_at, ended_at
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
jun_2023<-read_csv("202306-divvy-tripdata.csv")
## Rows: 719618 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (7): ride_id, rideable_type, start_station_name, start_station_id, end_...
## dbl  (4): start_lat, start_lng, end_lat, end_lng
## dttm (2): started_at, ended_at
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
jul_2023<-read_csv("202307-divvy-tripdata.csv")
## Rows: 767650 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (7): ride_id, rideable_type, start_station_name, start_station_id, end_...
## dbl  (4): start_lat, start_lng, end_lat, end_lng
## dttm (2): started_at, ended_at
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
aug_2023<-read_csv("202308-divvy-tripdata.csv")
## Rows: 771693 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (7): ride_id, rideable_type, start_station_name, start_station_id, end_...
## dbl  (4): start_lat, start_lng, end_lat, end_lng
## dttm (2): started_at, ended_at
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
sep_2023<-read_csv("202309-divvy-tripdata.csv")
## Rows: 666371 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (7): ride_id, rideable_type, start_station_name, start_station_id, end_...
## dbl  (4): start_lat, start_lng, end_lat, end_lng
## dttm (2): started_at, ended_at
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
oct_2023<-read_csv("202310-divvy-tripdata.csv")
## Rows: 537113 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (7): ride_id, rideable_type, start_station_name, start_station_id, end_...
## dbl  (4): start_lat, start_lng, end_lat, end_lng
## dttm (2): started_at, ended_at
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
nov_2023<-read_csv("202311-divvy-tripdata.csv")
## Rows: 362518 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (7): ride_id, rideable_type, start_station_name, start_station_id, end_...
## dbl  (4): start_lat, start_lng, end_lat, end_lng
## dttm (2): started_at, ended_at
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

Compare column names to each of the files for consistency prior to join files into one single data frame.Column names must match perfectly.

#compare column names
colnames(nov_2023)
##  [1] "ride_id"            "rideable_type"      "started_at"        
##  [4] "ended_at"           "start_station_name" "start_station_id"  
##  [7] "end_station_name"   "end_station_id"     "start_lat"         
## [10] "start_lng"          "end_lat"            "end_lng"           
## [13] "member_casual"
colnames(oct_2023)
##  [1] "ride_id"            "rideable_type"      "started_at"        
##  [4] "ended_at"           "start_station_name" "start_station_id"  
##  [7] "end_station_name"   "end_station_id"     "start_lat"         
## [10] "start_lng"          "end_lat"            "end_lng"           
## [13] "member_casual"
colnames(sep_2023)
##  [1] "ride_id"            "rideable_type"      "started_at"        
##  [4] "ended_at"           "start_station_name" "start_station_id"  
##  [7] "end_station_name"   "end_station_id"     "start_lat"         
## [10] "start_lng"          "end_lat"            "end_lng"           
## [13] "member_casual"
colnames(aug_2023)
##  [1] "ride_id"            "rideable_type"      "started_at"        
##  [4] "ended_at"           "start_station_name" "start_station_id"  
##  [7] "end_station_name"   "end_station_id"     "start_lat"         
## [10] "start_lng"          "end_lat"            "end_lng"           
## [13] "member_casual"
colnames(jul_2023)
##  [1] "ride_id"            "rideable_type"      "started_at"        
##  [4] "ended_at"           "start_station_name" "start_station_id"  
##  [7] "end_station_name"   "end_station_id"     "start_lat"         
## [10] "start_lng"          "end_lat"            "end_lng"           
## [13] "member_casual"
colnames(jun_2023)
##  [1] "ride_id"            "rideable_type"      "started_at"        
##  [4] "ended_at"           "start_station_name" "start_station_id"  
##  [7] "end_station_name"   "end_station_id"     "start_lat"         
## [10] "start_lng"          "end_lat"            "end_lng"           
## [13] "member_casual"
colnames(may_2023)
##  [1] "ride_id"            "rideable_type"      "started_at"        
##  [4] "ended_at"           "start_station_name" "start_station_id"  
##  [7] "end_station_name"   "end_station_id"     "start_lat"         
## [10] "start_lng"          "end_lat"            "end_lng"           
## [13] "member_casual"
colnames(apr_2023)
##  [1] "ride_id"            "rideable_type"      "started_at"        
##  [4] "ended_at"           "start_station_name" "start_station_id"  
##  [7] "end_station_name"   "end_station_id"     "start_lat"         
## [10] "start_lng"          "end_lat"            "end_lng"           
## [13] "member_casual"
colnames(mar_2023)
##  [1] "ride_id"            "rideable_type"      "started_at"        
##  [4] "ended_at"           "start_station_name" "start_station_id"  
##  [7] "end_station_name"   "end_station_id"     "start_lat"         
## [10] "start_lng"          "end_lat"            "end_lng"           
## [13] "member_casual"
colnames(feb_2023)
##  [1] "ride_id"            "rideable_type"      "started_at"        
##  [4] "ended_at"           "start_station_name" "start_station_id"  
##  [7] "end_station_name"   "end_station_id"     "start_lat"         
## [10] "start_lng"          "end_lat"            "end_lng"           
## [13] "member_casual"
colnames(jan_2023)
##  [1] "ride_id"            "rideable_type"      "started_at"        
##  [4] "ended_at"           "start_station_name" "start_station_id"  
##  [7] "end_station_name"   "end_station_id"     "start_lat"         
## [10] "start_lng"          "end_lat"            "end_lng"           
## [13] "member_casual"

Inspect the dataframes and look for incongruence.

#inspect the dataframes (jan-nov)
str(nov_2023)
## spc_tbl_ [362,518 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ride_id           : chr [1:362518] "4EAD8F1AD547356B" "6322270563BF5470" "B37BDE091ECA38E0" "CF0CA5DD26E4F90E" ...
##  $ rideable_type     : chr [1:362518] "electric_bike" "electric_bike" "electric_bike" "classic_bike" ...
##  $ started_at        : POSIXct[1:362518], format: "2023-11-30 21:50:05" "2023-11-03 09:44:02" ...
##  $ ended_at          : POSIXct[1:362518], format: "2023-11-30 22:13:27" "2023-11-03 10:17:15" ...
##  $ start_station_name: chr [1:362518] "Millennium Park" "Broadway & Sheridan Rd" "State St & Pearson St" "Theater on the Lake" ...
##  $ start_station_id  : chr [1:362518] "13008" "13323" "TA1307000061" "TA1308000001" ...
##  $ end_station_name  : chr [1:362518] "Pine Grove Ave & Waveland Ave" "Broadway & Sheridan Rd" "State St & Pearson St" "Theater on the Lake" ...
##  $ end_station_id    : chr [1:362518] "TA1307000150" "13323" "TA1307000061" "TA1308000001" ...
##  $ start_lat         : num [1:362518] 41.9 42 41.9 41.9 41.9 ...
##  $ start_lng         : num [1:362518] -87.6 -87.7 -87.6 -87.6 -87.6 ...
##  $ end_lat           : num [1:362518] 41.9 42 41.9 41.9 41.9 ...
##  $ end_lng           : num [1:362518] -87.6 -87.6 -87.6 -87.6 -87.6 ...
##  $ member_casual     : chr [1:362518] "member" "member" "member" "member" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   ride_id = col_character(),
##   ..   rideable_type = col_character(),
##   ..   started_at = col_datetime(format = ""),
##   ..   ended_at = col_datetime(format = ""),
##   ..   start_station_name = col_character(),
##   ..   start_station_id = col_character(),
##   ..   end_station_name = col_character(),
##   ..   end_station_id = col_character(),
##   ..   start_lat = col_double(),
##   ..   start_lng = col_double(),
##   ..   end_lat = col_double(),
##   ..   end_lng = col_double(),
##   ..   member_casual = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
str(oct_2023)
## spc_tbl_ [537,113 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ride_id           : chr [1:537113] "4449097279F8BBE7" "9CF060543CA7B439" "667F21F4D6BDE69C" "F92714CC6B019B96" ...
##  $ rideable_type     : chr [1:537113] "classic_bike" "electric_bike" "electric_bike" "classic_bike" ...
##  $ started_at        : POSIXct[1:537113], format: "2023-10-08 10:36:26" "2023-10-11 17:23:59" ...
##  $ ended_at          : POSIXct[1:537113], format: "2023-10-08 10:49:19" "2023-10-11 17:36:08" ...
##  $ start_station_name: chr [1:537113] "Orleans St & Chestnut St (NEXT Apts)" "Desplaines St & Kinzie St" "Orleans St & Chestnut St (NEXT Apts)" "Desplaines St & Kinzie St" ...
##  $ start_station_id  : chr [1:537113] "620" "TA1306000003" "620" "TA1306000003" ...
##  $ end_station_name  : chr [1:537113] "Sheffield Ave & Webster Ave" "Sheffield Ave & Webster Ave" "Franklin St & Lake St" "Franklin St & Lake St" ...
##  $ end_station_id    : chr [1:537113] "TA1309000033" "TA1309000033" "TA1307000111" "TA1307000111" ...
##  $ start_lat         : num [1:537113] 41.9 41.9 41.9 41.9 41.9 ...
##  $ start_lng         : num [1:537113] -87.6 -87.6 -87.6 -87.6 -87.6 ...
##  $ end_lat           : num [1:537113] 41.9 41.9 41.9 41.9 41.9 ...
##  $ end_lng           : num [1:537113] -87.7 -87.7 -87.6 -87.6 -87.6 ...
##  $ member_casual     : chr [1:537113] "member" "member" "member" "member" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   ride_id = col_character(),
##   ..   rideable_type = col_character(),
##   ..   started_at = col_datetime(format = ""),
##   ..   ended_at = col_datetime(format = ""),
##   ..   start_station_name = col_character(),
##   ..   start_station_id = col_character(),
##   ..   end_station_name = col_character(),
##   ..   end_station_id = col_character(),
##   ..   start_lat = col_double(),
##   ..   start_lng = col_double(),
##   ..   end_lat = col_double(),
##   ..   end_lng = col_double(),
##   ..   member_casual = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
str(sep_2023)
## spc_tbl_ [666,371 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ride_id           : chr [1:666371] "011C1903BF4E2E28" "87DB80E048A1BF9F" "7C2EB7AF669066E3" "57D197B010269CE3" ...
##  $ rideable_type     : chr [1:666371] "classic_bike" "classic_bike" "electric_bike" "classic_bike" ...
##  $ started_at        : POSIXct[1:666371], format: "2023-09-23 00:27:50" "2023-09-02 09:26:43" ...
##  $ ended_at          : POSIXct[1:666371], format: "2023-09-23 00:33:27" "2023-09-02 09:38:19" ...
##  $ start_station_name: chr [1:666371] "Halsted St & Wrightwood Ave" "Clark St & Drummond Pl" "Financial Pl & Ida B Wells Dr" "Clark St & Drummond Pl" ...
##  $ start_station_id  : chr [1:666371] "TA1309000061" "TA1307000142" "SL-010" "TA1307000142" ...
##  $ end_station_name  : chr [1:666371] "Sheffield Ave & Wellington Ave" "Racine Ave & Fullerton Ave" "Racine Ave & 15th St" "Racine Ave & Belmont Ave" ...
##  $ end_station_id    : chr [1:666371] "TA1307000052" "TA1306000026" "13304" "TA1308000019" ...
##  $ start_lat         : num [1:666371] 41.9 41.9 41.9 41.9 41.9 ...
##  $ start_lng         : num [1:666371] -87.6 -87.6 -87.6 -87.6 -87.6 ...
##  $ end_lat           : num [1:666371] 41.9 41.9 41.9 41.9 41.9 ...
##  $ end_lng           : num [1:666371] -87.7 -87.7 -87.7 -87.7 -87.7 ...
##  $ member_casual     : chr [1:666371] "member" "member" "member" "member" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   ride_id = col_character(),
##   ..   rideable_type = col_character(),
##   ..   started_at = col_datetime(format = ""),
##   ..   ended_at = col_datetime(format = ""),
##   ..   start_station_name = col_character(),
##   ..   start_station_id = col_character(),
##   ..   end_station_name = col_character(),
##   ..   end_station_id = col_character(),
##   ..   start_lat = col_double(),
##   ..   start_lng = col_double(),
##   ..   end_lat = col_double(),
##   ..   end_lng = col_double(),
##   ..   member_casual = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
str(aug_2023)
## spc_tbl_ [771,693 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ride_id           : chr [1:771693] "903C30C2D810A53B" "F2FB18A98E110A2B" "D0DEC7C94E4663DA" "E0DDDC5F84747ED9" ...
##  $ rideable_type     : chr [1:771693] "electric_bike" "electric_bike" "electric_bike" "electric_bike" ...
##  $ started_at        : POSIXct[1:771693], format: "2023-08-19 15:41:53" "2023-08-18 15:30:18" ...
##  $ ended_at          : POSIXct[1:771693], format: "2023-08-19 15:53:36" "2023-08-18 15:45:25" ...
##  $ start_station_name: chr [1:771693] "LaSalle St & Illinois St" "Clark St & Randolph St" "Clark St & Randolph St" "Wells St & Elm St" ...
##  $ start_station_id  : chr [1:771693] "13430" "TA1305000030" "TA1305000030" "KA1504000135" ...
##  $ end_station_name  : chr [1:771693] "Clark St & Elm St" NA NA NA ...
##  $ end_station_id    : chr [1:771693] "TA1307000039" NA NA NA ...
##  $ start_lat         : num [1:771693] 41.9 41.9 41.9 41.9 41.9 ...
##  $ start_lng         : num [1:771693] -87.6 -87.6 -87.6 -87.6 -87.6 ...
##  $ end_lat           : num [1:771693] 41.9 41.9 41.9 41.9 41.9 ...
##  $ end_lng           : num [1:771693] -87.6 -87.6 -87.6 -87.6 -87.7 ...
##  $ member_casual     : chr [1:771693] "member" "member" "member" "member" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   ride_id = col_character(),
##   ..   rideable_type = col_character(),
##   ..   started_at = col_datetime(format = ""),
##   ..   ended_at = col_datetime(format = ""),
##   ..   start_station_name = col_character(),
##   ..   start_station_id = col_character(),
##   ..   end_station_name = col_character(),
##   ..   end_station_id = col_character(),
##   ..   start_lat = col_double(),
##   ..   start_lng = col_double(),
##   ..   end_lat = col_double(),
##   ..   end_lng = col_double(),
##   ..   member_casual = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
str(jul_2023)
## spc_tbl_ [767,650 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ride_id           : chr [1:767650] "9340B064F0AEE130" "D1460EE3CE0D8AF8" "DF41BE31B895A25E" "9624A293749EF703" ...
##  $ rideable_type     : chr [1:767650] "electric_bike" "classic_bike" "classic_bike" "electric_bike" ...
##  $ started_at        : POSIXct[1:767650], format: "2023-07-23 20:06:14" "2023-07-23 17:05:07" ...
##  $ ended_at          : POSIXct[1:767650], format: "2023-07-23 20:22:44" "2023-07-23 17:18:37" ...
##  $ start_station_name: chr [1:767650] "Kedzie Ave & 110th St" "Western Ave & Walton St" "Western Ave & Walton St" "Racine Ave & Randolph St" ...
##  $ start_station_id  : chr [1:767650] "20204" "KA1504000103" "KA1504000103" "13155" ...
##  $ end_station_name  : chr [1:767650] "Public Rack - Racine Ave & 109th Pl" "Milwaukee Ave & Grand Ave" "Damen Ave & Pierce Ave" "Clinton St & Madison St" ...
##  $ end_station_id    : chr [1:767650] "877" "13033" "TA1305000041" "TA1305000032" ...
##  $ start_lat         : num [1:767650] 41.7 41.9 41.9 41.9 42 ...
##  $ start_lng         : num [1:767650] -87.7 -87.7 -87.7 -87.7 -87.7 ...
##  $ end_lat           : num [1:767650] 41.7 41.9 41.9 41.9 42 ...
##  $ end_lng           : num [1:767650] -87.7 -87.6 -87.7 -87.6 -87.6 ...
##  $ member_casual     : chr [1:767650] "member" "member" "member" "member" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   ride_id = col_character(),
##   ..   rideable_type = col_character(),
##   ..   started_at = col_datetime(format = ""),
##   ..   ended_at = col_datetime(format = ""),
##   ..   start_station_name = col_character(),
##   ..   start_station_id = col_character(),
##   ..   end_station_name = col_character(),
##   ..   end_station_id = col_character(),
##   ..   start_lat = col_double(),
##   ..   start_lng = col_double(),
##   ..   end_lat = col_double(),
##   ..   end_lng = col_double(),
##   ..   member_casual = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
str(jun_2023)
## spc_tbl_ [719,618 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ride_id           : chr [1:719618] "6F1682AC40EB6F71" "622A1686D64948EB" "3C88859D926253B4" "EAD8A5E0259DEC88" ...
##  $ rideable_type     : chr [1:719618] "electric_bike" "electric_bike" "electric_bike" "electric_bike" ...
##  $ started_at        : POSIXct[1:719618], format: "2023-06-05 13:34:12" "2023-06-05 01:30:22" ...
##  $ ended_at          : POSIXct[1:719618], format: "2023-06-05 14:31:56" "2023-06-05 01:33:06" ...
##  $ start_station_name: chr [1:719618] NA NA NA NA ...
##  $ start_station_id  : chr [1:719618] NA NA NA NA ...
##  $ end_station_name  : chr [1:719618] NA NA NA NA ...
##  $ end_station_id    : chr [1:719618] NA NA NA NA ...
##  $ start_lat         : num [1:719618] 41.9 41.9 42 42 42 ...
##  $ start_lng         : num [1:719618] -87.7 -87.7 -87.7 -87.7 -87.7 ...
##  $ end_lat           : num [1:719618] 41.9 41.9 41.9 42 42 ...
##  $ end_lng           : num [1:719618] -87.7 -87.7 -87.6 -87.7 -87.7 ...
##  $ member_casual     : chr [1:719618] "member" "member" "member" "member" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   ride_id = col_character(),
##   ..   rideable_type = col_character(),
##   ..   started_at = col_datetime(format = ""),
##   ..   ended_at = col_datetime(format = ""),
##   ..   start_station_name = col_character(),
##   ..   start_station_id = col_character(),
##   ..   end_station_name = col_character(),
##   ..   end_station_id = col_character(),
##   ..   start_lat = col_double(),
##   ..   start_lng = col_double(),
##   ..   end_lat = col_double(),
##   ..   end_lng = col_double(),
##   ..   member_casual = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
str(may_2023)
## spc_tbl_ [604,827 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ride_id           : chr [1:604827] "0D9FA920C3062031" "92485E5FB5888ACD" "FB144B3FC8300187" "DDEB93BC2CE9AA77" ...
##  $ rideable_type     : chr [1:604827] "electric_bike" "electric_bike" "electric_bike" "classic_bike" ...
##  $ started_at        : POSIXct[1:604827], format: "2023-05-07 19:53:48" "2023-05-06 18:54:08" ...
##  $ ended_at          : POSIXct[1:604827], format: "2023-05-07 19:58:32" "2023-05-06 19:03:35" ...
##  $ start_station_name: chr [1:604827] "Southport Ave & Belmont Ave" "Southport Ave & Belmont Ave" "Halsted St & 21st St" "Carpenter St & Huron St" ...
##  $ start_station_id  : chr [1:604827] "13229" "13229" "13162" "13196" ...
##  $ end_station_name  : chr [1:604827] NA NA NA "Damen Ave & Cortland St" ...
##  $ end_station_id    : chr [1:604827] NA NA NA "13133" ...
##  $ start_lat         : num [1:604827] 41.9 41.9 41.9 41.9 42 ...
##  $ start_lng         : num [1:604827] -87.7 -87.7 -87.6 -87.7 -87.7 ...
##  $ end_lat           : num [1:604827] 41.9 41.9 41.9 41.9 41.9 ...
##  $ end_lng           : num [1:604827] -87.7 -87.7 -87.7 -87.7 -87.7 ...
##  $ member_casual     : chr [1:604827] "member" "member" "member" "member" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   ride_id = col_character(),
##   ..   rideable_type = col_character(),
##   ..   started_at = col_datetime(format = ""),
##   ..   ended_at = col_datetime(format = ""),
##   ..   start_station_name = col_character(),
##   ..   start_station_id = col_character(),
##   ..   end_station_name = col_character(),
##   ..   end_station_id = col_character(),
##   ..   start_lat = col_double(),
##   ..   start_lng = col_double(),
##   ..   end_lat = col_double(),
##   ..   end_lng = col_double(),
##   ..   member_casual = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
str(apr_2023)
## spc_tbl_ [426,590 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ride_id           : chr [1:426590] "8FE8F7D9C10E88C7" "34E4ED3ADF1D821B" "5296BF07A2F77CB5" "40759916B76D5D52" ...
##  $ rideable_type     : chr [1:426590] "electric_bike" "electric_bike" "electric_bike" "electric_bike" ...
##  $ started_at        : POSIXct[1:426590], format: "2023-04-02 08:37:28" "2023-04-19 11:29:02" ...
##  $ ended_at          : POSIXct[1:426590], format: "2023-04-02 08:41:37" "2023-04-19 11:52:12" ...
##  $ start_station_name: chr [1:426590] NA NA NA NA ...
##  $ start_station_id  : chr [1:426590] NA NA NA NA ...
##  $ end_station_name  : chr [1:426590] NA NA NA NA ...
##  $ end_station_id    : chr [1:426590] NA NA NA NA ...
##  $ start_lat         : num [1:426590] 41.8 41.9 41.9 41.9 41.9 ...
##  $ start_lng         : num [1:426590] -87.6 -87.7 -87.7 -87.7 -87.7 ...
##  $ end_lat           : num [1:426590] 41.8 41.9 41.9 41.9 41.9 ...
##  $ end_lng           : num [1:426590] -87.6 -87.7 -87.7 -87.7 -87.6 ...
##  $ member_casual     : chr [1:426590] "member" "member" "member" "member" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   ride_id = col_character(),
##   ..   rideable_type = col_character(),
##   ..   started_at = col_datetime(format = ""),
##   ..   ended_at = col_datetime(format = ""),
##   ..   start_station_name = col_character(),
##   ..   start_station_id = col_character(),
##   ..   end_station_name = col_character(),
##   ..   end_station_id = col_character(),
##   ..   start_lat = col_double(),
##   ..   start_lng = col_double(),
##   ..   end_lat = col_double(),
##   ..   end_lng = col_double(),
##   ..   member_casual = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
str(mar_2023)
## spc_tbl_ [258,678 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ride_id           : chr [1:258678] "6842AA605EE9FBB3" "F984267A75B99A8C" "FF7CF57CFE026D02" "6B61B916032CB6D6" ...
##  $ rideable_type     : chr [1:258678] "electric_bike" "electric_bike" "classic_bike" "classic_bike" ...
##  $ started_at        : POSIXct[1:258678], format: "2023-03-16 08:20:34" "2023-03-04 14:07:06" ...
##  $ ended_at          : POSIXct[1:258678], format: "2023-03-16 08:22:52" "2023-03-04 14:15:31" ...
##  $ start_station_name: chr [1:258678] "Clark St & Armitage Ave" "Public Rack - Kedzie Ave & Argyle St" "Orleans St & Chestnut St (NEXT Apts)" "Desplaines St & Kinzie St" ...
##  $ start_station_id  : chr [1:258678] "13146" "491" "620" "TA1306000003" ...
##  $ end_station_name  : chr [1:258678] "Larrabee St & Webster Ave" NA "Clark St & Randolph St" "Sheffield Ave & Kingsbury St" ...
##  $ end_station_id    : chr [1:258678] "13193" NA "TA1305000030" "13154" ...
##  $ start_lat         : num [1:258678] 41.9 42 41.9 41.9 41.9 ...
##  $ start_lng         : num [1:258678] -87.6 -87.7 -87.6 -87.6 -87.7 ...
##  $ end_lat           : num [1:258678] 41.9 42 41.9 41.9 41.9 ...
##  $ end_lng           : num [1:258678] -87.6 -87.7 -87.6 -87.7 -87.7 ...
##  $ member_casual     : chr [1:258678] "member" "member" "member" "member" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   ride_id = col_character(),
##   ..   rideable_type = col_character(),
##   ..   started_at = col_datetime(format = ""),
##   ..   ended_at = col_datetime(format = ""),
##   ..   start_station_name = col_character(),
##   ..   start_station_id = col_character(),
##   ..   end_station_name = col_character(),
##   ..   end_station_id = col_character(),
##   ..   start_lat = col_double(),
##   ..   start_lng = col_double(),
##   ..   end_lat = col_double(),
##   ..   end_lng = col_double(),
##   ..   member_casual = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
str(feb_2023)
## spc_tbl_ [190,445 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ride_id           : chr [1:190445] "CBCD0D7777F0E45F" "F3EC5FCE5FF39DE9" "E54C1F27FA9354FF" "3D561E04F739CC45" ...
##  $ rideable_type     : chr [1:190445] "classic_bike" "electric_bike" "classic_bike" "electric_bike" ...
##  $ started_at        : POSIXct[1:190445], format: "2023-02-14 11:59:42" "2023-02-15 13:53:48" ...
##  $ ended_at          : POSIXct[1:190445], format: "2023-02-14 12:13:38" "2023-02-15 13:59:08" ...
##  $ start_station_name: chr [1:190445] "Southport Ave & Clybourn Ave" "Clarendon Ave & Gordon Ter" "Southport Ave & Clybourn Ave" "Southport Ave & Clybourn Ave" ...
##  $ start_station_id  : chr [1:190445] "TA1309000030" "13379" "TA1309000030" "TA1309000030" ...
##  $ end_station_name  : chr [1:190445] "Clark St & Schiller St" "Sheridan Rd & Lawrence Ave" "Aberdeen St & Monroe St" "Franklin St & Adams St (Temp)" ...
##  $ end_station_id    : chr [1:190445] "TA1309000024" "TA1309000041" "13156" "TA1309000008" ...
##  $ start_lat         : num [1:190445] 41.9 42 41.9 41.9 41.8 ...
##  $ start_lng         : num [1:190445] -87.7 -87.6 -87.7 -87.7 -87.6 ...
##  $ end_lat           : num [1:190445] 41.9 42 41.9 41.9 41.8 ...
##  $ end_lng           : num [1:190445] -87.6 -87.7 -87.7 -87.6 -87.6 ...
##  $ member_casual     : chr [1:190445] "casual" "casual" "member" "member" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   ride_id = col_character(),
##   ..   rideable_type = col_character(),
##   ..   started_at = col_datetime(format = ""),
##   ..   ended_at = col_datetime(format = ""),
##   ..   start_station_name = col_character(),
##   ..   start_station_id = col_character(),
##   ..   end_station_name = col_character(),
##   ..   end_station_id = col_character(),
##   ..   start_lat = col_double(),
##   ..   start_lng = col_double(),
##   ..   end_lat = col_double(),
##   ..   end_lng = col_double(),
##   ..   member_casual = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>
str(jan_2023)
## spc_tbl_ [190,301 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ride_id           : chr [1:190301] "F96D5A74A3E41399" "13CB7EB698CEDB88" "BD88A2E670661CE5" "C90792D034FED968" ...
##  $ rideable_type     : chr [1:190301] "electric_bike" "classic_bike" "electric_bike" "classic_bike" ...
##  $ started_at        : POSIXct[1:190301], format: "2023-01-21 20:05:42" "2023-01-10 15:37:36" ...
##  $ ended_at          : POSIXct[1:190301], format: "2023-01-21 20:16:33" "2023-01-10 15:46:05" ...
##  $ start_station_name: chr [1:190301] "Lincoln Ave & Fullerton Ave" "Kimbark Ave & 53rd St" "Western Ave & Lunt Ave" "Kimbark Ave & 53rd St" ...
##  $ start_station_id  : chr [1:190301] "TA1309000058" "TA1309000037" "RP-005" "TA1309000037" ...
##  $ end_station_name  : chr [1:190301] "Hampden Ct & Diversey Ave" "Greenwood Ave & 47th St" "Valli Produce - Evanston Plaza" "Greenwood Ave & 47th St" ...
##  $ end_station_id    : chr [1:190301] "202480.0" "TA1308000002" "599" "TA1308000002" ...
##  $ start_lat         : num [1:190301] 41.9 41.8 42 41.8 41.8 ...
##  $ start_lng         : num [1:190301] -87.6 -87.6 -87.7 -87.6 -87.6 ...
##  $ end_lat           : num [1:190301] 41.9 41.8 42 41.8 41.8 ...
##  $ end_lng           : num [1:190301] -87.6 -87.6 -87.7 -87.6 -87.6 ...
##  $ member_casual     : chr [1:190301] "member" "member" "casual" "member" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   ride_id = col_character(),
##   ..   rideable_type = col_character(),
##   ..   started_at = col_datetime(format = ""),
##   ..   ended_at = col_datetime(format = ""),
##   ..   start_station_name = col_character(),
##   ..   start_station_id = col_character(),
##   ..   end_station_name = col_character(),
##   ..   end_station_id = col_character(),
##   ..   start_lat = col_double(),
##   ..   start_lng = col_double(),
##   ..   end_lat = col_double(),
##   ..   end_lng = col_double(),
##   ..   member_casual = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>

Confirm if the dataframes are bindable.

#confirm if dataframes are bindable
compare_df_cols_same(jan_2023,feb_2023,mar_2023,apr_2023,
                     may_2023,jun_2023,jul_2023,aug_2023,
                     sep_2023,oct_2023,nov_2023)
## [1] TRUE

Combine data into a single data frame: “total_trips_2023”.

#combine dataframes into single frame
total_trips_2023<-bind_rows(jan_2023,feb_2023,mar_2023,apr_2023,may_2023,jun_2023,jul_2023,aug_2023,sep_2023,oct_2023,nov_2023)

3. PROCESS

Cleaning and manipulation of data

Inspect data frame “total_trips_2023” to see if needs cleaning.

#inspect new clean data frame
colnames(total_trips_2023)
##  [1] "ride_id"            "rideable_type"      "started_at"        
##  [4] "ended_at"           "start_station_name" "start_station_id"  
##  [7] "end_station_name"   "end_station_id"     "start_lat"         
## [10] "start_lng"          "end_lat"            "end_lng"           
## [13] "member_casual"

Number of rows.

#number of rows
nrow(total_trips_2023)
## [1] 5495804

Dimension of data frame.

#dataframe dimension
dim(total_trips_2023)
## [1] 5495804      13

List of columns and data types(numeric, character, etc.).

#list of columns and data types
str(total_trips_2023)
## spc_tbl_ [5,495,804 × 13] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ride_id           : chr [1:5495804] "F96D5A74A3E41399" "13CB7EB698CEDB88" "BD88A2E670661CE5" "C90792D034FED968" ...
##  $ rideable_type     : chr [1:5495804] "electric_bike" "classic_bike" "electric_bike" "classic_bike" ...
##  $ started_at        : POSIXct[1:5495804], format: "2023-01-21 20:05:42" "2023-01-10 15:37:36" ...
##  $ ended_at          : POSIXct[1:5495804], format: "2023-01-21 20:16:33" "2023-01-10 15:46:05" ...
##  $ start_station_name: chr [1:5495804] "Lincoln Ave & Fullerton Ave" "Kimbark Ave & 53rd St" "Western Ave & Lunt Ave" "Kimbark Ave & 53rd St" ...
##  $ start_station_id  : chr [1:5495804] "TA1309000058" "TA1309000037" "RP-005" "TA1309000037" ...
##  $ end_station_name  : chr [1:5495804] "Hampden Ct & Diversey Ave" "Greenwood Ave & 47th St" "Valli Produce - Evanston Plaza" "Greenwood Ave & 47th St" ...
##  $ end_station_id    : chr [1:5495804] "202480.0" "TA1308000002" "599" "TA1308000002" ...
##  $ start_lat         : num [1:5495804] 41.9 41.8 42 41.8 41.8 ...
##  $ start_lng         : num [1:5495804] -87.6 -87.6 -87.7 -87.6 -87.6 ...
##  $ end_lat           : num [1:5495804] 41.9 41.8 42 41.8 41.8 ...
##  $ end_lng           : num [1:5495804] -87.6 -87.6 -87.7 -87.6 -87.6 ...
##  $ member_casual     : chr [1:5495804] "member" "member" "casual" "member" ...
##  - attr(*, "spec")=
##   .. cols(
##   ..   ride_id = col_character(),
##   ..   rideable_type = col_character(),
##   ..   started_at = col_datetime(format = ""),
##   ..   ended_at = col_datetime(format = ""),
##   ..   start_station_name = col_character(),
##   ..   start_station_id = col_character(),
##   ..   end_station_name = col_character(),
##   ..   end_station_id = col_character(),
##   ..   start_lat = col_double(),
##   ..   start_lng = col_double(),
##   ..   end_lat = col_double(),
##   ..   end_lng = col_double(),
##   ..   member_casual = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>

First six rows of data frame.

#Preview firt 6 rows
head(total_trips_2023)

Statistical summary of data.

#statistical summary
summary(total_trips_2023)
##    ride_id          rideable_type        started_at                    
##  Length:5495804     Length:5495804     Min.   :2023-01-01 00:01:58.00  
##  Class :character   Class :character   1st Qu.:2023-05-18 18:15:14.50  
##  Mode  :character   Mode  :character   Median :2023-07-16 13:09:35.50  
##                                        Mean   :2023-07-10 06:47:12.70  
##                                        3rd Qu.:2023-09-09 12:49:02.75  
##                                        Max.   :2023-11-30 23:59:14.00  
##                                                                        
##     ended_at                      start_station_name start_station_id  
##  Min.   :2023-01-01 00:02:41.00   Length:5495804     Length:5495804    
##  1st Qu.:2023-05-18 18:32:05.75   Class :character   Class :character  
##  Median :2023-07-16 13:30:46.00   Mode  :character   Mode  :character  
##  Mean   :2023-07-10 07:05:34.51                                        
##  3rd Qu.:2023-09-09 13:10:32.00                                        
##  Max.   :2023-12-01 20:42:31.00                                        
##                                                                        
##  end_station_name   end_station_id       start_lat       start_lng     
##  Length:5495804     Length:5495804     Min.   :41.63   Min.   :-87.94  
##  Class :character   Class :character   1st Qu.:41.88   1st Qu.:-87.66  
##  Mode  :character   Mode  :character   Median :41.90   Median :-87.64  
##                                        Mean   :41.90   Mean   :-87.65  
##                                        3rd Qu.:41.93   3rd Qu.:-87.63  
##                                        Max.   :42.07   Max.   :-87.46  
##                                                                        
##     end_lat         end_lng       member_casual     
##  Min.   : 0.00   Min.   :-88.16   Length:5495804    
##  1st Qu.:41.88   1st Qu.:-87.66   Class :character  
##  Median :41.90   Median :-87.64   Mode  :character  
##  Mean   :41.90   Mean   :-87.65                     
##  3rd Qu.:41.93   3rd Qu.:-87.63                     
##  Max.   :42.18   Max.   :  0.00                     
##  NA's   :6751    NA's   :6751

Check for duplicate rows by “ride_id”.

#check duplicate rows
num_duplicate_rows <-sum(duplicated(total_trips_2023$ride_id))
cat("Number of rows with duplicates:", num_duplicate_rows, "\n")
## Number of rows with duplicates: 0

Verify total distinct rows (5,495,804).

#total distinct rows
n_distinct(total_trips_2023)
## [1] 5495804

Confirm the column member_casual is correctly input with two characters “member” or “casual”.

#member or casual
total_trips_2023 %>%
  group_by(member_casual) %>%
  summarize(distinct_lable= n_distinct(member_casual))
table(total_trips_2023$member_casual)
## 
##  casual  member 
## 2007507 3488297

Add date, month, day, and year for each ride.

#add date, month, day, year, for each ride
total_trips_2023$date <- as.Date(total_trips_2023$started_at) 
total_trips_2023$month <- format(as.Date(total_trips_2023$date), "%m")
total_trips_2023$month<-factor(format(as.Date(paste("2019", total_trips_2023$month, "01", sep = "-")), "%b"), levels = month.abb)
total_trips_2023$day <- format(as.Date(total_trips_2023$date), "%d")
total_trips_2023$year <- format(as.Date(total_trips_2023$date), "%Y")
total_trips_2023$day_of_week <- format(as.Date(total_trips_2023$date), "%A")

Calculate trip duration (in seconds).

#calculate trip_duration: ended_at - started_at
total_trips_2023$trip_duration<-difftime(total_trips_2023$ended_at,total_trips_2023$started_at)

Inspect columns.

#inspect structure of columns
str(total_trips_2023)
## spc_tbl_ [5,495,804 × 19] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
##  $ ride_id           : chr [1:5495804] "F96D5A74A3E41399" "13CB7EB698CEDB88" "BD88A2E670661CE5" "C90792D034FED968" ...
##  $ rideable_type     : chr [1:5495804] "electric_bike" "classic_bike" "electric_bike" "classic_bike" ...
##  $ started_at        : POSIXct[1:5495804], format: "2023-01-21 20:05:42" "2023-01-10 15:37:36" ...
##  $ ended_at          : POSIXct[1:5495804], format: "2023-01-21 20:16:33" "2023-01-10 15:46:05" ...
##  $ start_station_name: chr [1:5495804] "Lincoln Ave & Fullerton Ave" "Kimbark Ave & 53rd St" "Western Ave & Lunt Ave" "Kimbark Ave & 53rd St" ...
##  $ start_station_id  : chr [1:5495804] "TA1309000058" "TA1309000037" "RP-005" "TA1309000037" ...
##  $ end_station_name  : chr [1:5495804] "Hampden Ct & Diversey Ave" "Greenwood Ave & 47th St" "Valli Produce - Evanston Plaza" "Greenwood Ave & 47th St" ...
##  $ end_station_id    : chr [1:5495804] "202480.0" "TA1308000002" "599" "TA1308000002" ...
##  $ start_lat         : num [1:5495804] 41.9 41.8 42 41.8 41.8 ...
##  $ start_lng         : num [1:5495804] -87.6 -87.6 -87.7 -87.6 -87.6 ...
##  $ end_lat           : num [1:5495804] 41.9 41.8 42 41.8 41.8 ...
##  $ end_lng           : num [1:5495804] -87.6 -87.6 -87.7 -87.6 -87.6 ...
##  $ member_casual     : chr [1:5495804] "member" "member" "casual" "member" ...
##  $ date              : Date[1:5495804], format: "2023-01-21" "2023-01-10" ...
##  $ month             : Factor w/ 12 levels "Jan","Feb","Mar",..: 1 1 1 1 1 1 1 1 1 1 ...
##  $ day               : chr [1:5495804] "21" "10" "02" "22" ...
##  $ year              : chr [1:5495804] "2023" "2023" "2023" "2023" ...
##  $ day_of_week       : chr [1:5495804] "Saturday" "Tuesday" "Monday" "Sunday" ...
##  $ trip_duration     : 'difftime' num [1:5495804] 651 509 794 526 ...
##   ..- attr(*, "units")= chr "secs"
##  - attr(*, "spec")=
##   .. cols(
##   ..   ride_id = col_character(),
##   ..   rideable_type = col_character(),
##   ..   started_at = col_datetime(format = ""),
##   ..   ended_at = col_datetime(format = ""),
##   ..   start_station_name = col_character(),
##   ..   start_station_id = col_character(),
##   ..   end_station_name = col_character(),
##   ..   end_station_id = col_character(),
##   ..   start_lat = col_double(),
##   ..   start_lng = col_double(),
##   ..   end_lat = col_double(),
##   ..   end_lng = col_double(),
##   ..   member_casual = col_character()
##   .. )
##  - attr(*, "problems")=<externalptr>

Convert “trip_duration” from factor to numeric.

#convert trip duration to numeric
is.factor(total_trips_2023$trip_duration)
## [1] FALSE
#confirm trip duration is numeric
total_trips_2023$trip_duration <- as.numeric(as.character(total_trips_2023$trip_duration))
is.numeric(total_trips_2023$trip_duration)
## [1] TRUE

Remove “bad” data in which Divvy took out bikes from docks for quality or remove negative trip_duration.

#remove bad data
total_trips_20203_v2 <- total_trips_2023 %>%
  filter(started_at <= ended_at)
rows_filtered_out <-nrow(total_trips_2023) - nrow(total_trips_20203_v2)
cat ("Number of rows filtered out:", rows_filtered_out, "\n")
## Number of rows filtered out: 262

4. ANALYZE

Descriptive analysis

Average ride in seconds.

#mean calculation
mean(total_trips_20203_v2$trip_duration)
## [1] 1102.846

Midpoint number in the ascending array of trip duration.

#median calculation
median(total_trips_20203_v2$trip_duration)
## [1] 577

Longest ride.

#maximum calculation
max(total_trips_20203_v2$trip_duration)
## [1] 5909344

Shortest ride.

#minimum calculation
min(total_trips_20203_v2$trip_duration)
## [1] 0

Summary of trip duration.

#summary of trip duration
summary(total_trips_20203_v2$trip_duration)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       0     328     577    1103    1026 5909344

Compare trip duration between member and casual riders.

#compare member and casual
aggregate(total_trips_20203_v2$trip_duration~total_trips_20203_v2$member_casual, FUN=mean)
aggregate(total_trips_20203_v2$trip_duration~total_trips_20203_v2$member_casual, FUN=median)
aggregate(total_trips_20203_v2$trip_duration~total_trips_20203_v2$member_casual, FUN=max)
aggregate(total_trips_20203_v2$trip_duration~total_trips_20203_v2$member_casual, FUN=min)

Average ride time by each day between member riders and casual riders.

#average trip duration by day
total_trips_20203_v2$day_of_week <- ordered(total_trips_20203_v2$day_of_week, levels=c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"))
aggregate(total_trips_20203_v2$trip_duration ~ total_trips_20203_v2$member_casual+total_trips_20203_v2$day_of_week, FUN=mean)

Analyze ridership data by member/casual and weekday.

#create weekday field, calculates the no. of rides, average duration, and sorts
total_trips_20203_v2 %>% 
  mutate(weekday = wday(started_at, label = TRUE)) %>%  
  group_by(member_casual, weekday) %>%  
  summarize(number_of_rides = n(), average_duration = mean(trip_duration)) %>%      
  arrange(member_casual, weekday)                               
## `summarise()` has grouped output by 'member_casual'. You can override using the
## `.groups` argument.

Total number of trips.

#ride summary between member and casual
ride_summary<-total_trips_20203_v2 %>%
  group_by(member_casual) %>%
  summarize(total_rides = n()) %>%
  mutate(percentage = (total_rides / sum(total_rides)) * 100)
print(ride_summary)
## # A tibble: 2 × 3
##   member_casual total_rides percentage
##   <chr>               <int>      <dbl>
## 1 casual            2007367       36.5
## 2 member            3488175       63.5

5. SHARE

Data visualization

We’ll be using ggplot2 (tivdyverse package) to cover the visualizations of results.

color_theme<-c("#FFBE98", "#3A544B", "#F16A66")
#total number of rides in 2023
total_trips_20203_v2 %>%
  group_by(member_casual) %>%
  summarize(percentage= n() / nrow(total_trips_20203_v2) * 100, 
            total_users =n()) %>%
  ggplot(aes(x= "", y=percentage, fill=member_casual)) +
  geom_bar(stat="identity", width= 1, color="white") +
  coord_polar(theta="y") + #create pie chart
  labs(title="Number of Riders Using Cyclistic 2023 (Jan-Nov)", x=NULL, y=NULL, fill="User Types") +
  theme_void()+
geom_text(aes(label=paste0(total_users, " ", "(", round(percentage), "%)")), position=position_stack(vjust=0.5), color="white")+
  scale_fill_manual(values=color_theme)

#number of rides per month
total_trips_20203_v2 %>%
  group_by(month, member_casual) %>%
  summarize(number_of_rides =n(), .group='drop') %>%
  ggplot(aes(x = month, y=number_of_rides, fill=member_casual)) +
  geom_col(position="dodge") +
   scale_y_continuous(labels=scales::comma)+
  labs(title="Total Number of Rides per Month (Jan-Nov)", 
       x="Month",
       y="Number of Riders",
       fill= "User Types") +
   scale_fill_manual(values=color_theme)
## `summarise()` has grouped output by 'month'. You can override using the
## `.groups` argument.

#average ride duration per month
total_trips_20203_v2 %>%
  group_by(member_casual, month) %>%
  summarise(number_of_rides = n(),
            average_duration = mean(trip_duration/60)) %>%
  ggplot(aes(x = month, y = average_duration, color= member_casual, group=member_casual)) +
  geom_point() +
  geom_line()+
  labs(title = "Average Ride Duration per Month (Jan-Nov)",
       x = "Month",
       y = "Average Duration (minutes)",
       color = "User Types") +
  theme_minimal() +
  scale_color_manual(values=color_theme)
## `summarise()` has grouped output by 'member_casual'. You can override using the
## `.groups` argument.

#number of rides per day
total_trips_20203_v2 %>% 
  mutate(weekday = wday(started_at, label = TRUE)) %>% 
  group_by(member_casual, weekday) %>%
  summarise(number_of_rides = n()
            ,average_duration = mean(trip_duration/60)) %>% 
  arrange(member_casual, weekday)  %>% 
  ggplot(aes(x = weekday, y = number_of_rides, fill = member_casual)) +
  geom_col(position = "dodge") + 
  scale_y_continuous(labels=scales::comma)+
  labs(title="Total Number of Riders per Day", 
       x= "Day of the Week",
       y= "Number of Riders",
       fill= "User Types") +
  scale_fill_manual(values=color_theme)
## `summarise()` has grouped output by 'member_casual'. You can override using the
## `.groups` argument.

#average duration per day
total_trips_20203_v2 %>% 
  mutate(weekday = wday(started_at, label = TRUE)) %>% 
  group_by(member_casual, weekday) %>%
  summarise(number_of_rides = n()
            ,average_duration = mean(trip_duration/60)) %>% 
  arrange(member_casual, weekday)  %>% 
 ggplot(aes(x = weekday, y = average_duration, color= member_casual, group=member_casual)) +
  geom_point() +
  geom_line()+
  labs(title = "Average Ride Duration Day of the Week",
       x = "Day of the Week",
       y = "Average Duration (minutes)",
       color = "User Types") +
  theme_minimal() +
  scale_color_manual(values=color_theme)
## `summarise()` has grouped output by 'member_casual'. You can override using the
## `.groups` argument.

Year 2023 (Jan-Nov) Analysis

Base on the five plots we can make the following analyse:

  • The pie chart for the year of 2023 shows member riders achieved the highest proportion of rides than casual riders(63% versus 37%).
  • Both casual and member riders prefer warmer months of June, July, and August. Casual riders peak at the month of August; however, there is a steep decline in the months of January, February, and March.
  • Member riders show a stable average trip duration throughout the year, with a steady decline in the cold months of January, February, and March.
  • Regarding average ride time each day per week, we see a similar trend of longer trip duration in casual riders than member riders. Also, we see a similar trend in both groups where average ride time hits peak values on the weekend.
  • In summary, while the member riders have the most bike-share trips, it is the casual riders that have the highest trip duration through out the year, indicating demands toward extracurricular activities. On the other hand, member riders take shorter trips as a daily transportation for commuting to work or school.

6. ACT

Recommendations

To recap, Ms. Moreno requested three recommendations based on the result findings. The following are our top three recommendations based on the user types:

  1. Membership Promotions
  1. Communications
  1. Feedback Surveys