I am new to R and doing my first case study but stuck on my first task from the Google Data Analytics course. I have 2 columns in 1 of 12 datasets that is formatted as 'col_character()' that needs to be changed to the same format of the other datasets as 'col_datetime(format = "") before combining them into one dataset.
I've been testing different suggestions from this forum and other online sources, but none seem to work. Here are a few that I have tried:
m05_2022$started_at <- as_datetime(m05_2022$started_at, format="%m/%d/%Y %H,%M,%S")
m05_2022$started_at <- mdy_hms(m05_2022$started_at)
str(m05_2022)
m05_2022 <- mutate(m05_2022, started_at=as.datetime(started_at), ended_at= as.datetime(ended_at))
Below is the script that I have started with:
title: "R Notebook"
output:
html_document:
df_print: paged
Install required packages
tidyverse for data import and wrangling
lubridate for date functions
ggplot for visualization
install.packages("tidyverse")
library(tidyverse)
library(lubridate)
library(ggplot2)
#Upload datasets
setwd("/Users/ToddS/Desktop/Cyclistic_Data")
getwd()
m05_2022 <- read_csv("202205-divvy-tripdata.csv")
m06_2022 <- read_csv("202206-divvy-tripdata.csv")
m07_2022 <- read_csv("202207-divvy-tripdata.csv")
m08_2022 <- read_csv("202208-divvy-tripdata.csv")
m09_2022 <- read_csv("202209-divvy-tripdata.csv")
m10_2022 <- read_csv("202210-divvy-tripdata.csv")
m11_2022 <- read_csv("202211-divvy-tripdata.csv")
m12_2022 <- read_csv("202212-divvy-tripdata.csv")
m01_2023 <- read_csv("202301-divvy-tripdata.csv")
m02_2023 <- read_csv("202302-divvy-tripdata.csv")
m03_2023 <- read_csv("202303-divvy-tripdata.csv")
m04_2023 <- read_csv("202304-divvy-tripdata.csv")
Compare column names
colnames(m05_2022)
colnames(m06_2022)
colnames(m07_2022)
colnames(m08_2022)
colnames(m09_2022)
colnames(m10_2022)
colnames(m11_2022)
colnames(m12_2022)
colnames(m01_2023)
colnames(m02_2023)
colnames(m03_2023)
colnames(m04_2023)
Inspect the dataframes
str(m05_2022)
str(m06_2022)
str(m07_2022)
str(m08_2022)
str(m09_2022)
str(m10_2022)
str(m11_2022)
str(m12_2022)
str(m01_2023)
str(m02_2023)
str(m03_2023)
str(m04_2023)
Converting m05_2022 columns 'started_at' and 'ended_at' from character to datetime
???
Any insight would be greatly appreciated!