I have an excel dataset in which there are dates and time points as follows:
record_id date_E1 time_E1 date_E2 time_E2 ...
1 2019/8/24 09:00:00 2019/8/25 18:00:00
I would like to construct a variable which contains the number of hours past the first time and date, (09:00 a.m 2019/8/24)
. When I read the excel file with
read_excel("C:/visit.xlsx")
the time_E1 .. appears as 0.3750000 0.7736111 0.4131944 0.4131944
,
and the date appears as 43640 43640 43641 43642
, in R. I use visit_dates<-as.Date(as.numeric(visit_date_L$Day), origin = "1899-12-30")
to convert dates to 2019-8-24
and .. but do not know how to convert time of the day and convert to the hours past the first time point. What I expect is a vector like: 0, 42, ... hours past first time point.
I have used the following code:
as.POSIXct(visit_times, format = " %H-%M", origin = "09:00:00"),
but it returns a NULL vector. After that I could use the following code to transpose and combine date and time data:
visit_time <- subset(MY_visit, select = c(record_id, time_E1, ...)
visit_date <- subset(MY_visit, select = c(record_id, date_E1,...)
visit_time_L <- melt(visit_time, id.vars=c("record_id"))
visit_date_L <- melt(visit_date, id.vars=c("record_id"))
names(visit_time_L)[names(visit_time_L)=="value"] <- "time"
names(visit_date_L)[names(visit_date_L)=="value"] <- "Day"
visit_all <- cbind(visit_time_L, visit_date_L)
Any ideas how can I solve this problem?