Hi, I apologize if I didn't make my data clear earlier. I am working on the Google Certification Program Capstone Project. This is how my sample dataset looks like. I need to calculate the trip length which is ended_at-started_at.
#libraries install
library(tidyverse)
library(tidyr)
library(ggplot2)
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
#sample data set
df <- data.frame(
stringsAsFactors = FALSE,
NA,
started_at = c("1/21/2020 20:06",
"1/30/2020 14:22",
"1/9/2020 19:29",
"1/6/2020 16:17",
"1/30/2020 8:37"),
ended_at = c("1/21/2020 20:14",
"1/30/2020 14:26",
"1/9/2020 19:32",
"1/6/2020 16:25",
"1/30/2020 8:42")
)
#There statement is returning 0 secs in trip_length
trip_2021$trip_length <- difftime(trip_2021$ended_at,trip_2021$started_at)
#> Error in as.POSIXct(time1): object 'trip_2021' not found
Created on 2021-09-08 by the reprex package (v2.0.1)