This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
In 2016, Cyclistic launched a successful bike-share offering. Since then, the program has grown to a fleet of 5,824 bicycles that are geo-tracked 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 anytime.
Until now, Cyclistic’s marketing strategy relied on building general awareness and appealing to broad consumer segments. One approach that helped make these things possible was the flexibility of its pricing plans: single-ride passes, full-day passes, and annual memberships. Customers who purchase single-ride or full-day passes are referred to as casual riders. Customers who purchase annual memberships are Cyclistic members.
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, Lily Moreno, the director of marketing believes that maximizing the number of annual members will be key to future growth. Rather than creating a marketing campaign that targets all-new customers, Moreno believes there is a very good chance to convert casual riders into members. She notes that casual riders are already aware of the Cyclistic program and have chosen Cyclistic for their mobility needs.
Moreno has set a clear goal: Design marketing strategies aimed at converting casual riders into annual members. In order to do that, however, the marketing analyst team needs to better understand how annual members and casual riders differ, why casual riders would buy a membership, and how digital media could affect their marketing tactics.
My role: I am a junior data analyst, working in the marketing analyst team at Cyclistic.
Overall goal for the entire team: Design marketing strategies aimed at converting casual riders into annual members.
I have been asked to do a specific business task (mentioned below).
The business task is done by following through all the steps of data analysis.
1.Ask 2.Prepare 3.Process 4.Analyze 5.Share 6.Act
Business task: How do annual members and casual riders use Cyclistic bike differently?
Data Source: The data used for solving the above business task is downloaded from the Cyclistic trip data.. I used data from the period Nov 2022 - Oct 2023.
I downloaded the data and stored it locally in my computer. It is organized by month and year and stored as zip files.
Data credibility The data is reliable and original. It is comprehensive and has the required information to solve the business problem It is current and cited from this site Click here
Data License
The data has been made available by Motivate International Inc under this license
Data-privacy issues prohibits me from using riders’ personally identifiable information and I won’t be able to connect pass purchases to credit card numbers to determine if casual riders live in the Cyclistic service area or if they have purchased multiple single passes.
I have used the R programming language for processing and analyzing data and making it ready for creating visualizations.
library(tidyverse) #helps wrangle data
## Warning: package 'tidyverse' was built under R version 4.3.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ 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(janitor) #helps with data cleaning
## Warning: package 'janitor' was built under R version 4.3.2
##
## Attaching package: 'janitor'
##
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
setwd("~/Data analysis/Module 8/Case study_cyclistic/CSV files")
Nov_22 <- read_csv("202211-divvy-tripdata.csv")
## Rows: 337735 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): ride_id, rideable_type, started_at, ended_at, start_station_name, s...
## dbl (5): start_lat, start_lng, end_lat, end_lng, day_of_week
##
## ℹ 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.
Dec_22 <- read_csv("202212-divvy-tripdata.csv")
## Rows: 181806 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): ride_id, rideable_type, started_at, ended_at, start_station_name, s...
## dbl (5): start_lat, start_lng, end_lat, end_lng, day_of_week
##
## ℹ 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.
Jan_23 <- read_csv("202301-divvy-tripdata.csv")
## Rows: 190301 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): ride_id, rideable_type, started_at, ended_at, start_station_name, s...
## dbl (5): start_lat, start_lng, end_lat, end_lng, day_of_week
##
## ℹ 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_23 <- read_csv("202302-divvy-tripdata.csv")
## Rows: 190445 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): ride_id, rideable_type, started_at, ended_at, start_station_name, s...
## dbl (5): start_lat, start_lng, end_lat, end_lng, day_of_week
##
## ℹ 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_23 <- read_csv("202303-divvy-tripdata.csv")
## Rows: 258678 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): ride_id, rideable_type, started_at, ended_at, start_station_name, s...
## dbl (5): start_lat, start_lng, end_lat, end_lng, day_of_week
##
## ℹ 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_23 <- read_csv("202304-divvy-tripdata.csv")
## Rows: 426590 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): ride_id, rideable_type, started_at, ended_at, start_station_name, s...
## dbl (5): start_lat, start_lng, end_lat, end_lng, day_of_week
##
## ℹ 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_23 <- read_csv("202305-divvy-tripdata.csv")
## Rows: 604827 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): ride_id, rideable_type, started_at, ended_at, start_station_name, s...
## dbl (5): start_lat, start_lng, end_lat, end_lng, day_of_week
##
## ℹ 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_23 <- read_csv("202306-divvy-tripdata.csv")
## Rows: 719618 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): ride_id, rideable_type, started_at, ended_at, start_station_name, s...
## dbl (5): start_lat, start_lng, end_lat, end_lng, day_of_week
##
## ℹ 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_23 <- read_csv("202307-divvy-tripdata.csv")
## Rows: 767650 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): ride_id, rideable_type, started_at, ended_at, start_station_name, s...
## dbl (5): start_lat, start_lng, end_lat, end_lng, day_of_week
##
## ℹ 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_23 <- read_csv("202308-divvy-tripdata.csv")
## Rows: 771693 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): ride_id, rideable_type, started_at, ended_at, start_station_name, s...
## dbl (5): start_lat, start_lng, end_lat, end_lng, day_of_week
##
## ℹ 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_23 <- read_csv("202309-divvy-tripdata.csv")
## Rows: 666371 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): ride_id, rideable_type, started_at, ended_at, start_station_name, s...
## dbl (5): start_lat, start_lng, end_lat, end_lng, day_of_week
##
## ℹ 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_23 <- read_csv("202310-divvy-tripdata.csv")
## Rows: 537113 Columns: 14
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (9): ride_id, rideable_type, started_at, ended_at, start_station_name, s...
## dbl (5): start_lat, start_lng, end_lat, end_lng, day_of_week
##
## ℹ 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.
I’m attaching a picture of one of these csv files to give an idea of how the data looks
knitr::include_graphics("Sample_csv.png")
summary(Nov_22)
## ride_id rideable_type started_at ended_at
## Length:337735 Length:337735 Length:337735 Length:337735
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_station_name start_station_id end_station_name end_station_id
## Length:337735 Length:337735 Length:337735 Length:337735
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_lat start_lng end_lat end_lng
## Min. :41.65 Min. :-87.84 Min. : 0.00 Min. :-87.84
## 1st Qu.:41.88 1st Qu.:-87.66 1st Qu.:41.88 1st Qu.:-87.66
## Median :41.90 Median :-87.64 Median :41.90 Median :-87.65
## Mean :41.90 Mean :-87.65 Mean :41.90 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.07 Max. :-87.52 Max. :42.08 Max. : 0.00
## NA's :230 NA's :230
## member_casual day_of_week
## Length:337735 Min. :1.000
## Class :character 1st Qu.:3.000
## Mode :character Median :4.000
## Mean :3.987
## 3rd Qu.:5.000
## Max. :7.000
##
summary(Dec_22)
## ride_id rideable_type started_at ended_at
## Length:181806 Length:181806 Length:181806 Length:181806
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_station_name start_station_id end_station_name end_station_id
## Length:181806 Length:181806 Length:181806 Length:181806
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_lat start_lng end_lat end_lng
## Min. :41.65 Min. :-87.83 Min. :41.64 Min. :-87.84
## 1st Qu.:41.88 1st Qu.:-87.66 1st Qu.:41.88 1st Qu.:-87.66
## Median :41.90 Median :-87.65 Median :41.90 Median :-87.65
## Mean :41.90 Mean :-87.65 Mean :41.90 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.07 Max. :-87.53 Max. :42.07 Max. :-87.52
## NA's :128 NA's :128
## member_casual day_of_week
## Length:181806 Min. :1.00
## Class :character 1st Qu.:3.00
## Mode :character Median :4.00
## Mean :4.19
## 3rd Qu.:6.00
## Max. :7.00
##
summary(Jan_23)
## ride_id rideable_type started_at ended_at
## Length:190301 Length:190301 Length:190301 Length:190301
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_station_name start_station_id end_station_name end_station_id
## Length:190301 Length:190301 Length:190301 Length:190301
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_lat start_lng end_lat end_lng
## Min. :41.65 Min. :-87.83 Min. :41.65 Min. :-87.84
## 1st Qu.:41.88 1st Qu.:-87.66 1st Qu.:41.88 1st Qu.:-87.66
## Median :41.89 Median :-87.64 Median :41.89 Median :-87.64
## Mean :41.90 Mean :-87.65 Mean :41.90 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.07 Max. :-87.53 Max. :42.08 Max. :-87.53
## NA's :127 NA's :127
## member_casual day_of_week
## Length:190301 Min. :1.00
## Class :character 1st Qu.:2.00
## Mode :character Median :4.00
## Mean :3.88
## 3rd Qu.:5.00
## Max. :7.00
##
summary(Feb_23)
## ride_id rideable_type started_at ended_at
## Length:190445 Length:190445 Length:190445 Length:190445
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_station_name start_station_id end_station_name end_station_id
## Length:190445 Length:190445 Length:190445 Length:190445
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_lat start_lng end_lat end_lng
## Min. :41.65 Min. :-87.84 Min. :41.65 Min. :-87.90
## 1st Qu.:41.88 1st Qu.:-87.66 1st Qu.:41.88 1st Qu.:-87.66
## Median :41.89 Median :-87.64 Median :41.89 Median :-87.64
## Mean :41.90 Mean :-87.65 Mean :41.90 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.07 Max. :-87.53 Max. :42.07 Max. :-87.53
## NA's :116 NA's :116
## member_casual day_of_week
## Length:190445 Min. :1.000
## Class :character 1st Qu.:2.000
## Mode :character Median :3.000
## Mean :3.733
## 3rd Qu.:5.000
## Max. :7.000
##
summary(Mar_23)
## ride_id rideable_type started_at ended_at
## Length:258678 Length:258678 Length:258678 Length:258678
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_station_name start_station_id end_station_name end_station_id
## Length:258678 Length:258678 Length:258678 Length:258678
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_lat start_lng end_lat end_lng
## Min. :41.65 Min. :-87.83 Min. :41.63 Min. :-87.85
## 1st Qu.:41.88 1st Qu.:-87.66 1st Qu.:41.88 1st Qu.:-87.66
## Median :41.89 Median :-87.64 Median :41.89 Median :-87.64
## Mean :41.90 Mean :-87.65 Mean :41.90 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.07 Max. :-87.53 Max. :42.08 Max. :-87.52
## NA's :183 NA's :183
## member_casual day_of_week
## Length:258678 Min. :1.000
## Class :character 1st Qu.:3.000
## Mode :character Median :4.000
## Mean :4.071
## 3rd Qu.:5.000
## Max. :7.000
##
summary(Apr_23)
## ride_id rideable_type started_at ended_at
## Length:426590 Length:426590 Length:426590 Length:426590
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_station_name start_station_id end_station_name end_station_id
## Length:426590 Length:426590 Length:426590 Length:426590
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_lat start_lng end_lat end_lng
## Min. :41.65 Min. :-87.83 Min. :41.65 Min. :-88.11
## 1st Qu.:41.88 1st Qu.:-87.66 1st Qu.:41.88 1st Qu.:-87.66
## Median :41.90 Median :-87.64 Median :41.90 Median :-87.64
## Mean :41.90 Mean :-87.65 Mean :41.90 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.07 Max. :-87.52 Max. :42.08 Max. :-87.53
## NA's :435 NA's :435
## member_casual day_of_week
## Length:426590 Min. :1.000
## Class :character 1st Qu.:3.000
## Mode :character Median :5.000
## Mean :4.321
## 3rd Qu.:6.000
## Max. :7.000
##
summary(May_23)
## ride_id rideable_type started_at ended_at
## Length:604827 Length:604827 Length:604827 Length:604827
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_station_name start_station_id end_station_name end_station_id
## Length:604827 Length:604827 Length:604827 Length:604827
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_lat start_lng end_lat end_lng
## Min. :41.65 Min. :-87.87 Min. :41.62 Min. :-87.91
## 1st Qu.:41.88 1st Qu.:-87.66 1st Qu.:41.88 1st Qu.:-87.66
## Median :41.90 Median :-87.64 Median :41.90 Median :-87.64
## Mean :41.90 Mean :-87.65 Mean :41.90 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.07 Max. :-87.53 Max. :42.11 Max. :-87.53
## NA's :710 NA's :710
## member_casual day_of_week
## Length:604827 Min. :1.000
## Class :character 1st Qu.:2.000
## Mode :character Median :4.000
## Mean :3.964
## 3rd Qu.:6.000
## Max. :7.000
##
summary(Jun_23)
## ride_id rideable_type started_at ended_at
## Length:719618 Length:719618 Length:719618 Length:719618
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_station_name start_station_id end_station_name end_station_id
## Length:719618 Length:719618 Length:719618 Length:719618
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_lat start_lng end_lat end_lng
## Min. :41.64 Min. :-87.87 Min. : 0.00 Min. :-88.16
## 1st Qu.:41.88 1st Qu.:-87.66 1st Qu.:41.88 1st Qu.:-87.66
## Median :41.90 Median :-87.64 Median :41.90 Median :-87.64
## Mean :41.91 Mean :-87.65 Mean :41.91 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.07 Max. :-87.53 Max. :42.11 Max. : 0.00
## NA's :889 NA's :889
## member_casual day_of_week
## Length:719618 Min. :1.000
## Class :character 1st Qu.:3.000
## Mode :character Median :5.000
## Mean :4.378
## 3rd Qu.:6.000
## Max. :7.000
##
summary(Jul_23)
## ride_id rideable_type started_at ended_at
## Length:767650 Length:767650 Length:767650 Length:767650
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_station_name start_station_id end_station_name end_station_id
## Length:767650 Length:767650 Length:767650 Length:767650
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_lat start_lng end_lat end_lng
## Min. :41.65 Min. :-87.92 Min. :41.61 Min. :-87.92
## 1st Qu.:41.88 1st Qu.:-87.66 1st Qu.:41.88 1st Qu.:-87.66
## Median :41.90 Median :-87.64 Median :41.90 Median :-87.64
## Mean :41.91 Mean :-87.65 Mean :41.91 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.07 Max. :-87.53 Max. :42.18 Max. :-87.51
## NA's :1254 NA's :1254
## member_casual day_of_week
## Length:767650 Min. :1.000
## Class :character 1st Qu.:2.000
## Mode :character Median :4.000
## Mean :4.032
## 3rd Qu.:6.000
## Max. :7.000
##
summary(Aug_23)
## ride_id rideable_type started_at ended_at
## Length:771693 Length:771693 Length:771693 Length:771693
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_station_name start_station_id end_station_name end_station_id
## Length:771693 Length:771693 Length:771693 Length:771693
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_lat start_lng end_lat end_lng
## Min. :41.63 Min. :-87.86 Min. : 0.00 Min. :-87.98
## 1st Qu.:41.88 1st Qu.:-87.66 1st Qu.:41.88 1st Qu.:-87.66
## Median :41.90 Median :-87.64 Median :41.90 Median :-87.64
## Mean :41.91 Mean :-87.65 Mean :41.91 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.07 Max. :-87.46 Max. :42.10 Max. : 0.00
## NA's :1257 NA's :1257
## member_casual day_of_week
## Length:771693 Min. :1.000
## Class :character 1st Qu.:3.000
## Mode :character Median :4.000
## Mean :4.146
## 3rd Qu.:6.000
## Max. :7.000
##
summary(Sep_23)
## ride_id rideable_type started_at ended_at
## Length:666371 Length:666371 Length:666371 Length:666371
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_station_name start_station_id end_station_name end_station_id
## Length:666371 Length:666371 Length:666371 Length:666371
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_lat start_lng end_lat end_lng
## Min. :41.65 Min. :-87.94 Min. :41.62 Min. :-87.94
## 1st Qu.:41.88 1st Qu.:-87.66 1st Qu.:41.88 1st Qu.:-87.66
## Median :41.90 Median :-87.64 Median :41.90 Median :-87.65
## Mean :41.90 Mean :-87.65 Mean :41.90 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.07 Max. :-87.53 Max. :42.12 Max. :-87.49
## NA's :838 NA's :838
## member_casual day_of_week
## Length:666371 Min. :1.000
## Class :character 1st Qu.:3.000
## Mode :character Median :5.000
## Mean :4.377
## 3rd Qu.:6.000
## Max. :7.000
##
summary(Oct_23)
## ride_id rideable_type started_at ended_at
## Length:537113 Length:537113 Length:537113 Length:537113
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_station_name start_station_id end_station_name end_station_id
## Length:537113 Length:537113 Length:537113 Length:537113
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_lat start_lng end_lat end_lng
## Min. :41.64 Min. :-87.86 Min. :41.64 Min. :-87.99
## 1st Qu.:41.88 1st Qu.:-87.66 1st Qu.:41.88 1st Qu.:-87.66
## Median :41.90 Median :-87.64 Median :41.90 Median :-87.64
## Mean :41.90 Mean :-87.65 Mean :41.90 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.07 Max. :-87.52 Max. :42.07 Max. :-87.52
## NA's :592 NA's :592
## member_casual day_of_week
## Length:537113 Min. :1.000
## Class :character 1st Qu.:2.000
## Mode :character Median :4.000
## Mean :3.745
## 3rd Qu.:5.000
## Max. :7.000
##
This is a crucial step as we need to make sure that the column names of each individual data frames and their data types match. Only then we can combine them together without any issues.This is done using the compare_df_cols() function from the janitor package.
compare_df_cols(Nov_22,Dec_22,Jan_23,Feb_23,Mar_23,Apr_23,May_23,Jun_23,Jul_23,Aug_23,Sep_23,Oct_23, return = 'mismatch')
## [1] column_name Nov_22 Dec_22 Jan_23 Feb_23 Mar_23
## [7] Apr_23 May_23 Jun_23 Jul_23 Aug_23 Sep_23
## [13] Oct_23
## <0 rows> (or 0-length row.names)
This shows that all the column names and their data types match.
all_rides <- bind_rows(Nov_22,Dec_22,Jan_23,Feb_23,Mar_23,Apr_23,May_23,Jun_23,Jul_23,Aug_23,Sep_23,Oct_23)
Now let’s take an initial overall look at our combined data frame
head(all_rides)
## # A tibble: 6 × 14
## ride_id rideable_type started_at ended_at start_station_name start_station_id
## <chr> <chr> <chr> <chr> <chr> <chr>
## 1 BCC66FC… electric_bike 11/10/202… 11/10/2… Canal St & Adams … 13011
## 2 772AB67… classic_bike 11/4/2022… 11/4/20… Canal St & Adams … 13011
## 3 585EAD0… classic_bike 11/21/202… 11/21/2… Indiana Ave & Roo… SL-005
## 4 91C4E7E… classic_bike 11/25/202… 11/25/2… Indiana Ave & Roo… SL-005
## 5 709206A… classic_bike 11/29/202… 11/29/2… Indiana Ave & Roo… SL-005
## 6 11DE62E… classic_bike 11/4/2022… 11/4/20… Streeter Dr & Gra… 13022
## # ℹ 8 more variables: end_station_name <chr>, end_station_id <chr>,
## # start_lat <dbl>, start_lng <dbl>, end_lat <dbl>, end_lng <dbl>,
## # member_casual <chr>, day_of_week <dbl>
colnames(all_rides)
## [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" "day_of_week"
nrow(all_rides)
## [1] 5652827
summary(all_rides)
## ride_id rideable_type started_at ended_at
## Length:5652827 Length:5652827 Length:5652827 Length:5652827
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_station_name start_station_id end_station_name end_station_id
## Length:5652827 Length:5652827 Length:5652827 Length:5652827
## Class :character Class :character Class :character Class :character
## Mode :character Mode :character Mode :character Mode :character
##
##
##
##
## start_lat start_lng end_lat end_lng
## Min. :41.63 Min. :-87.94 Min. : 0.00 Min. :-88.16
## 1st Qu.:41.88 1st Qu.:-87.66 1st Qu.:41.88 1st Qu.:-87.66
## Median :41.90 Median :-87.64 Median :41.90 Median :-87.64
## Mean :41.90 Mean :-87.65 Mean :41.90 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.07 Max. :-87.46 Max. :42.18 Max. : 0.00
## NA's :6759 NA's :6759
## member_casual day_of_week
## Length:5652827 Min. :1.000
## Class :character 1st Qu.:2.000
## Mode :character Median :4.000
## Mean :4.109
## 3rd Qu.:6.000
## Max. :7.000
##
all_rides$started_at <- strptime(all_rides$started_at, "%m/%d/%Y %H:%M")
all_rides$ended_at <- strptime(all_rides$ended_at, "%m/%d/%Y %H:%M")
all_rides$date <- as.Date(all_rides$started_at, "%m/%d/%Y")
all_rides$month <- format(as.Date(all_rides$date), "%m")
all_rides$day <- format(as.Date(all_rides$date), "%d")
all_rides$year <- format(as.Date(all_rides$date), "%Y")
all_rides$day_of_week <- format(as.Date(all_rides$date), "%A")
all_rides$ride_length <- difftime(all_rides$ended_at,all_rides$started_at,units="min")
is.numeric(all_rides$ride_length)
## [1] FALSE
all_rides$ride_length <- as.numeric(all_rides$ride_length)
is.numeric(all_rides$ride_length)
## [1] TRUE
Now let’s get a summary of our combined data frame
summary(all_rides)
## ride_id rideable_type started_at
## Length:5652827 Length:5652827 Min. :2022-11-01 00:00:00.00
## Class :character Class :character 1st Qu.:2023-04-18 07:59:00.00
## Mode :character Mode :character Median :2023-06-27 06:46:00.00
## Mean :2023-06-11 03:40:15.92
## 3rd Qu.:2023-08-23 12:49:00.00
## Max. :2023-10-31 23:59:00.00
##
## ended_at start_station_name start_station_id
## Min. :2022-11-01 00:03:00.00 Length:5652827 Length:5652827
## 1st Qu.:2023-04-18 08:10:00.00 Class :character Class :character
## Median :2023-06-27 07:01:00.00 Mode :character Mode :character
## Mean :2023-06-11 03:58:31.68
## 3rd Qu.:2023-08-23 13:08:00.00
## Max. :2023-11-01 21:23:00.00
##
## end_station_name end_station_id start_lat start_lng
## Length:5652827 Length:5652827 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 day_of_week
## Min. : 0.00 Min. :-88.16 Length:5652827 Length:5652827
## 1st Qu.:41.88 1st Qu.:-87.66 Class :character Class :character
## Median :41.90 Median :-87.64 Mode :character Mode :character
## Mean :41.90 Mean :-87.65
## 3rd Qu.:41.93 3rd Qu.:-87.63
## Max. :42.18 Max. : 0.00
## NA's :6759 NA's :6759
## date month day year
## Min. :2022-11-01 Length:5652827 Length:5652827 Length:5652827
## 1st Qu.:2023-04-18 Class :character Class :character Class :character
## Median :2023-06-27 Mode :character Mode :character Mode :character
## Mean :2023-06-10
## 3rd Qu.:2023-08-23
## Max. :2023-10-31
##
## ride_length
## Min. : -82.00
## 1st Qu.: 5.00
## Median : 10.00
## Mean : 18.26
## 3rd Qu.: 17.00
## Max. :98489.00
##
head(all_rides)
## # A tibble: 6 × 19
## ride_id rideable_type started_at ended_at
## <chr> <chr> <dttm> <dttm>
## 1 BCC66FC6FAB27CC7 electric_bike 2022-11-10 06:21:00 2022-11-10 06:31:00
## 2 772AB67E902C180F classic_bike 2022-11-04 07:31:00 2022-11-04 07:46:00
## 3 585EAD07FDEC0152 classic_bike 2022-11-21 17:20:00 2022-11-21 17:34:00
## 4 91C4E7ED3C262FF9 classic_bike 2022-11-25 17:29:00 2022-11-25 17:45:00
## 5 709206A3104CABC8 classic_bike 2022-11-29 17:24:00 2022-11-29 17:42:00
## 6 11DE62E16D1A6BD1 classic_bike 2022-11-04 14:40:00 2022-11-04 14:52:00
## # ℹ 15 more variables: start_station_name <chr>, start_station_id <chr>,
## # end_station_name <chr>, end_station_id <chr>, start_lat <dbl>,
## # start_lng <dbl>, end_lat <dbl>, end_lng <dbl>, member_casual <chr>,
## # day_of_week <chr>, date <date>, month <chr>, day <chr>, year <chr>,
## # ride_length <dbl>
table(sign(all_rides$ride_length))
##
## -1 0 1
## 116 89354 5563357
In our final data frame we have to filter and just use the positive ride length values. Before we get to that, we need to do some more analysis.
sum(is.na(all_rides$start_station_name))
## [1] 866243
sum(is.na(all_rides$end_station_name))
## [1] 918796
unique(all_rides$member_casual)
## [1] "member" "casual"
unique(all_rides$rideable_type)
## [1] "electric_bike" "classic_bike" "docked_bike"
sum(duplicated(all_rides$ride_id))
## [1] 1955
all_rides_v2 <- all_rides %>% filter(all_rides$ride_length>0, !duplicated(all_rides$ride_id))
all_rides_final <- drop_na(all_rides_v2)
Now let’s have an overall look at our final data frame that we just created.
str(all_rides_final)
## tibble [4,227,884 × 19] (S3: tbl_df/tbl/data.frame)
## $ ride_id : chr [1:4227884] "BCC66FC6FAB27CC7" "772AB67E902C180F" "585EAD07FDEC0152" "91C4E7ED3C262FF9" ...
## $ rideable_type : chr [1:4227884] "electric_bike" "classic_bike" "classic_bike" "classic_bike" ...
## $ started_at : POSIXlt[1:4227884], format: "2022-11-10 06:21:00" "2022-11-04 07:31:00" ...
## $ ended_at : POSIXlt[1:4227884], format: "2022-11-10 06:31:00" "2022-11-04 07:46:00" ...
## $ start_station_name: chr [1:4227884] "Canal St & Adams St" "Canal St & Adams St" "Indiana Ave & Roosevelt Rd" "Indiana Ave & Roosevelt Rd" ...
## $ start_station_id : chr [1:4227884] "13011" "13011" "SL-005" "SL-005" ...
## $ end_station_name : chr [1:4227884] "St. Clair St & Erie St" "St. Clair St & Erie St" "St. Clair St & Erie St" "St. Clair St & Erie St" ...
## $ end_station_id : chr [1:4227884] "13016" "13016" "13016" "13016" ...
## $ start_lat : num [1:4227884] 41.9 41.9 41.9 41.9 41.9 ...
## $ start_lng : num [1:4227884] -87.6 -87.6 -87.6 -87.6 -87.6 ...
## $ end_lat : num [1:4227884] 41.9 41.9 41.9 41.9 41.9 ...
## $ end_lng : num [1:4227884] -87.6 -87.6 -87.6 -87.6 -87.6 ...
## $ member_casual : chr [1:4227884] "member" "member" "member" "member" ...
## $ day_of_week : chr [1:4227884] "Thursday" "Friday" "Monday" "Friday" ...
## $ date : Date[1:4227884], format: "2022-11-10" "2022-11-04" ...
## $ month : chr [1:4227884] "11" "11" "11" "11" ...
## $ day : chr [1:4227884] "10" "04" "21" "25" ...
## $ year : chr [1:4227884] "2022" "2022" "2022" "2022" ...
## $ ride_length : num [1:4227884] 10 15 14 16 18 12 10 9 10 7 ...
View(all_rides_final)
Below is a screenshot of the first few rows of all_rides_final data frame
knitr::include_graphics("all_rides_final.png")
This means that we need to know the mean,median, min and max values of ride length. All of these values can be obtained in one shot using the summary() function.
summary(all_rides_final$ride_length)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.00 6.00 10.00 16.15 18.00 12136.00
#this calculates the overall average ride length for casual and member riders
aggregate(all_rides_final$ride_length ~ all_rides_final$member_casual, FUN = mean)
## all_rides_final$member_casual all_rides_final$ride_length
## 1 casual 23.11608
## 2 member 12.27700
#this calculates the minimum ride length for casual and member riders
aggregate(all_rides_final$ride_length ~ all_rides_final$member_casual, FUN = min)
## all_rides_final$member_casual all_rides_final$ride_length
## 1 casual 1
## 2 member 1
#this calculates the maximum ride length for casual and member riders
aggregate(all_rides_final$ride_length ~ all_rides_final$member_casual, FUN =max)
## all_rides_final$member_casual all_rides_final$ride_length
## 1 casual 12136
## 2 member 1498
# this calculates the median value of ride length for casual and member riders
aggregate(all_rides_final$ride_length ~ all_rides_final$member_casual, FUN = median)
## all_rides_final$member_casual all_rides_final$ride_length
## 1 casual 13
## 2 member 9
aggregate(all_rides_final$ride_length ~ all_rides_final$member_casual + all_rides_final$day_of_week, FUN = mean)
## all_rides_final$member_casual all_rides_final$day_of_week
## 1 casual Friday
## 2 member Friday
## 3 casual Monday
## 4 member Monday
## 5 casual Saturday
## 6 member Saturday
## 7 casual Sunday
## 8 member Sunday
## 9 casual Thursday
## 10 member Thursday
## 11 casual Tuesday
## 12 member Tuesday
## 13 casual Wednesday
## 14 member Wednesday
## all_rides_final$ride_length
## 1 22.56583
## 2 12.22137
## 3 22.69673
## 4 11.67333
## 5 26.16616
## 6 13.73699
## 7 26.79985
## 8 13.77528
## 9 20.27248
## 10 11.76170
## 11 20.60010
## 12 11.78403
## 13 19.76064
## 14 11.74382
We can see that the days of the week are out of order. Let’s fix that
all_rides_final$day_of_week <- ordered(all_rides_final$day_of_week, levels = c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"))
Now let’s run the code for the average ride length by day of the week for casual vs member riders
aggregate(all_rides_final$ride_length ~ all_rides_final$member_casual + all_rides_final$day_of_week, FUN = mean)
## all_rides_final$member_casual all_rides_final$day_of_week
## 1 casual Sunday
## 2 member Sunday
## 3 casual Monday
## 4 member Monday
## 5 casual Tuesday
## 6 member Tuesday
## 7 casual Wednesday
## 8 member Wednesday
## 9 casual Thursday
## 10 member Thursday
## 11 casual Friday
## 12 member Friday
## 13 casual Saturday
## 14 member Saturday
## all_rides_final$ride_length
## 1 26.79985
## 2 13.77528
## 3 22.69673
## 4 11.67333
## 5 20.60010
## 6 11.78403
## 7 19.76064
## 8 11.74382
## 9 20.27248
## 10 11.76170
## 11 22.56583
## 12 12.22137
## 13 26.16616
## 14 13.73699
all_rides_final %>%
mutate(weekday = wday(started_at, label = TRUE)) %>% # creates weekday field using wday() function
group_by(member_casual,weekday) %>% # groups by rider type and weekday
summarise(number_of_rides = n(), average_duration = mean(ride_length)) %>% # calculates the number of rides and average duration
arrange(member_casual,weekday) # sorts
## `summarise()` has grouped output by 'member_casual'. You can override using the
## `.groups` argument.
## # A tibble: 14 × 4
## # Groups: member_casual [2]
## member_casual weekday number_of_rides average_duration
## <chr> <ord> <int> <dbl>
## 1 casual Sun 249451 26.8
## 2 casual Mon 172936 22.7
## 3 casual Tue 183727 20.6
## 4 casual Wed 183016 19.8
## 5 casual Thu 197807 20.3
## 6 casual Fri 225048 22.6
## 7 casual Sat 300407 26.2
## 8 member Sun 295656 13.8
## 9 member Mon 375762 11.7
## 10 member Tue 447969 11.8
## 11 member Wed 440735 11.7
## 12 member Thu 436902 11.8
## 13 member Fri 385404 12.2
## 14 member Sat 333064 13.7
all_rides_final %>%
mutate(weekday = wday(started_at, label = TRUE)) %>%
group_by(member_casual,weekday) %>%
summarise(number_of_rides = n(), average_duration = mean(ride_length)) %>%
arrange(member_casual,weekday) %>%
ggplot(aes(x=weekday,y=number_of_rides,fill=member_casual)) + geom_col(position="dodge")
## `summarise()` has grouped output by 'member_casual'. You can override using the
## `.groups` argument.
The graph shows us that member riders ride more number of bikes than casual riders in a week
all_rides_final %>%
mutate(weekday = wday(started_at, label = TRUE)) %>%
group_by(member_casual,weekday) %>%
summarise(number_of_rides = n(), average_duration = mean(ride_length)) %>%
arrange(member_casual,weekday) %>%
ggplot(aes(x=weekday,y=average_duration,fill=member_casual)) + geom_col(position="dodge")
## `summarise()` has grouped output by 'member_casual'. You can override using the
## `.groups` argument.
This graph shows that though member riders ride more number of bikes, it is the casual riders that ride their bikes for a long time.
Export the final file for further analysis
I created a final csv file and exported it for further analysis and visualization using Tableau
write.csv(all_rides_final, "C:\\Users\\susan\\OneDrive\\Documents\\Data analysis\\Module 8\\Case study_cyclistic\\Insights\\all_rides_export.csv", row.names=FALSE)