Hi Team,
I have a column which has date,time (1/8/2018 12:24:57 AM) with one more column ID. i have to calculate the total number of hours between the time period group by ID. Below is the code i am trying
I would use the lubridate package to first change your character date-times into numeric date-times of the POSIXct type. Notice that 1/8/2018 12:24:57 AM could be January 8 2018 or August 1 2018. If the month is the first digit in the date, try
real <- real %>% mutate(start.time = lubridate::mdy_hms(start.time)
If the day is the first digit, try
real <- real %>% mutate(start.time = lubridate::dmy_hms(start.time)
Thanks. I tried first converting using the POSIXct but it didnt work. It throwing warnings. All formats failed to parse. When i did str(real) its giving
Please post a small sample of your data and code as a reproducible example (reprex). This is done with the reprex package and information about using it is available in these two posts (and many other places): How to do a minimal reprex What's a reproducible example?
Your sample data doesn't have this format "%m/%d/%Y %H:%M:%S", apparently those are difftime values, not POSIXct values, so you should use hms() function instead.