How can I change the datatype in my dataframe from chr to time, without adding dates to it?
My dataframe is called exit_count and my column is called time.
When I use the head(exit_count)
I can see the table how it is supposed to, however when I use the str(exit_count)
I can see that my time coulmn is in chr-format.
Programing in R:
I have tried using the as.POSIXct()
:
exit_count$time <- as.POSIXct(exit_count$time,format="%H:%M")
however, this adds today's date which messes up with my dataset (I have a separate column for date).
I have tried the chron-package:
chron(times = exit_count$time, format="%H:%M")
however, it still doesn't work.
exit_count <- read.csv (Data/Exit count/exit_count_all_data.csv",
sep=";", dec=".", header=TRUE, stringsAsFactors=FALSE)
exit_count$date <- as.Date(as.POSIXct(exit_count$date, format="%d.%m.%Y", tz="GMT")) #This works
exit_count$time <- chron(times = exit_count$time,format="%H:%M") #However, neither this
exit_count$time <- as.POSIXct(exit_count$time,format="%H:%M") #Nor this
exit_count$time <- times(paste0(exit_count$date, "%H:%M")) #Nor this works (This was something that @Sotos wanted me to try, but it still doesn't work).
exit_count$time <- chron(times=exit_count$time) #Nor this. However, i get an output here - but this yields big numbers (e.g. 17911.93), which is not what I want.
I need for this to work in order to get my data frames and my plots to be correct for my masters thesis. Without me being an expert, I imagine it can be done in such a way that the date and the time can be in two separate columns and that the time can be in a datatype that R understands as time (like it does with the POSIX and date, that I have already manage to make).
Please help! Thanks :)