SnakePlissken
SnakePlissken

Reputation: 1

r Language - Difftime function - Why do I get an error?

I have two different variables (ended_at, started_at) containing times in a chr data type in a dataframe called all_trips.

Data from all_trips.

           started_at            ended_at 
1 2019-01-01 00:04:37 2019-01-01 00:11:07          
2 2019-01-01 00:08:13 2019-01-01 00:15:34          
3 2019-01-01 00:13:23 2019-01-01 00:27:12          
4 2019-01-01 00:13:45 2019-01-01 00:43:28           
5 2019-01-01 00:14:52 2019-01-01 00:20:56          
6 2019-01-01 00:15:33 2019-01-01 00:19:09

      

When I run this code:

all_trips$ride_length <- difftime(all_trips$ended_at,all_trips$started_at)

I get this error.

Error in as.POSIXlt.character(x, tz, ...) : 
  character string is not in a standard unambiguous format

What am I doing wrong? Thanks.

I'm supposed to get the difference between the two times. I tried changing the chr data type, but that didn't work. Probably because I didn't do it correctly.....

Upvotes: 0

Views: 106

Answers (2)

NoobDataAnalyst
NoobDataAnalyst

Reputation: 1

If this is the coursera case project I think it is, try deleting your files and data frames and the reloading the CSV files straight into your working directory and then re-run read.csv() to load with the new name and work from there.

Upvotes: 0

SnakePlissken
SnakePlissken

Reputation: 1

I think I spotted the problem. Most of the data is in YMD HMS format. After further review, some of it is in DMY HMS format

Upvotes: 0

Related Questions