variables in the dataset not found issues.

<! i have tried using different functions such to calculate duration from two different time variables "started_at" and "ended-at" from bike_share data set i keep getting not found.
i have installed and loaded
install.packages("readr")
install.packages("readr")
library(readr)
library(tibble)
the use
difftime() its not working

am a beginner in R, please kindly assist.
thank you.

-->

in addition, I tried using exists("variable_names") to see the variable names I got FALSE

You might be trying to do the same exercise that was discussed in this thread: Unable to Substract two columns in R

There's some hints in this comment and a small example in this comment

Because you're reading from a csv, the start end end datetimes are not numerical. You need to convert the character vectors started_at and ended_at to something that can be used to perform calculations. To do that, we can use the number of seconds that has passed since January 1, 1970, formatted as something that is a bit more readable than that. Right now for example, that's 1723547908 seconds, but it's much easier to read as "2024-08-13 07:18:28 EDT". So, here's a very simple example.

library(readr)
df <- read.csv("data/202004-divvy-tripdata.csv")
df$started_at <- as.POSIXct(df$started_at)
df$ended_at <- as.POSIXct(df$ended_at)
df$duration <- df$ended_at-df$started_at

dealing with dates and times is a PITA, TBH. The lubridate package is really nice and makes handling them much easier.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.