I'm relatively new to R and having trouble handling date and time data. I am analyzing data from a Zoom event which gives an attendee report with registration time, join time, and leave time. When I read in my csv file, those 3 variables are imported as character variables and take the format of month/day/year hour:minute (picture attached). When I use the as.date function, it only converts the date and the time is dropped entirely. How to I preserve the time as well?
You can use the as.POSIXct()
function.
Alternatively, you may find this more user-friendly:
Parse date-times with year, month, and day, hour, minute, and second components. — ymd_hms • lubridate (tidyverse.org)
Thanks. I've tried as.POSIXct() but get the error message: "Error in as.POSIXlt.character(x, tz, ...) :
character string is not in a standard unambiguous format"
You need to specify the format, too.
Check the help page ?as.POSIXct()
or use the lubridate function I linked. I don't know whether your data is day, then month or vice versa, so you'll have to specify the format or identify the appropriate function yourself.
Oh yes, I think this will work. Thank you!
If you choose to use lubridate, it looks like you might want something like:
lubridate::mdy_HM()
# or, if your data is day/month/year:
lubridate::dmy_HM()
Good luck!
This topic was automatically closed 7 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.