I am trying to combine times with it's corresponding date, but am having trouble. The dates and times are in one list where the date is followed by times for that date. This papptern continues in an irregular fashion.
Here's what I tried so far:
z = as.data.frame(c("2014-12-01", "7:00", "8:00", "9:00"))
z$x = llply(z[[1]], as.Date, format = "%Y-%m-%d")
names(z) = c("a", "b")
dp = function (x) {x = z$b
if(class(x) != "Date") {paste(z$a, x)} else {x = z$b}}
as.data.frame(llply(z, dp))[1]
And I get:
a
1 2014-12-01 16405
2 7:00 NA
3 8:00 NA
4 9:00 NA
I'm looking for:
a
1 2014-12-01
2 7:00 2014-12-01
3 8:00 2014-12-01
4 9:00 2014-12-01
Ideally, i'd like a solution to combine the date and time into a single date-time object.
Please help...thanks
If you need a date-time object
Or if you need it to be in the
format
as shown in the resultdata