I imported some data from Excel that has separate columns for "Date" and "Time". When I imported the "Time" column, it returned with 1899-12-31 19:00:00 with the date 1899-12-31 for every single time value.
I would like to create a new column that would combine the date from the "Date" column and time from the "Time" column so I can do some calculations.
# A tibble: 207 x 2
DoS ToS
<dttm> <dttm>
1 2018-01-27 00:00:00 1899-12-31 19:00:00
2 2018-02-07 00:00:00 1899-12-31 15:45:00
3 2018-02-13 00:00:00 1899-12-31 23:00:00
4 2018-02-15 00:00:00 1899-12-31 13:45:00
5 2018-02-16 00:00:00 1899-12-31 10:00:00
6 2018-02-19 00:00:00 1899-12-31 15:00:00
7 2018-02-20 00:00:00 1899-12-31 15:05:00
8 2018-02-21 00:00:00 1899-12-31 15:00:00
> dput(head(sample, 10))
structure(list(DoS = structure(c(1517011200, 1517961600, 1518480000,
1518652800, 1518739200, 1518998400, 1519084800, 1519171200, 1519257600,
1519862400), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
ToS = structure(c(-2209006800, -2209018500, -2208992400,
-2209025700, -2209039200, -2209021200, -2209020900, -2209021200,
-2209033800, -2209005000), class = c("POSIXct", "POSIXt"), tzone = "UTC")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -10L))
Is there some way I can extract the time values and paste it to the Date column?
Using base R, we can extract date from DoS and time from ToS and combine them together.
transform(sample, Datetime = as.POSIXct(paste(as.Date(DoS), format(ToS, "%T"))))
# DoS ToS Datetime
#1 2018-01-27 1899-12-31 19:00:00 2018-01-27 19:00:00
#2 2018-02-07 1899-12-31 15:45:00 2018-02-07 15:45:00
#3 2018-02-13 1899-12-31 23:00:00 2018-02-13 23:00:00
#4 2018-02-15 1899-12-31 13:45:00 2018-02-15 13:45:00
#5 2018-02-16 1899-12-31 10:00:00 2018-02-16 10:00:00
#6 2018-02-19 1899-12-31 15:00:00 2018-02-19 15:00:00
#7 2018-02-20 1899-12-31 15:05:00 2018-02-20 15:05:00
#8 2018-02-21 1899-12-31 15:00:00 2018-02-21 15:00:00
#9 2018-02-22 1899-12-31 11:30:00 2018-02-22 11:30:00
#10 2018-03-01 1899-12-31 19:30:00 2018-03-01 19:30:00
Related
I have a data frame with two date/time columns:
BeginTime EndTime Value
-----------------------------------------------------
1 2019-01-03 13:45:00 2019-01-03 17:30:00 41
2 2019-01-03 13:30:00 2019-01-03 14:30:00 20
3 2019-01-03 16:45:00 2019-01-03 19:00:00 23
That I need to transform into this:
Time Value
--------------------------------
1 2019-01-03 13:45:00 41
2 2019-01-03 14:00:00 41
3 2019-01-03 14:15:00 41
4 2019-01-03 14:30:00 41
5 2019-01-03 14:45:00 41
6 2019-01-03 15:00:00 41
7 2019-01-03 15:15:00 41
8 2019-01-03 13:30:00 20
9 2019-01-03 13:45:00 20
10 2019-01-03 14:00:00 20
11 2019-01-03 14:15:00 20
12 2019-01-03 16:45:00 23
But not sure how to do that. Any suggestions?
Code to create testdf
testdf <- data.frame(c("2019-01-03 13:45:00", "2019-01-03 13:30:00", "2019-01-03 16:45:00"),
c("2019-01-03 15:30:00", "2019-01-03 14:30:00", "2019-01-03 17:00:00"),
c(41,20,23))
colnames(testdf) <-c("BeginTime", "EndTime", "Value")
testdf$BeginTime <- as.POSIXct(testdf$BeginTime)
testdf$EndTime <- as.POSIXct(testdf$EndTime)
(I know there's probably a way to create the columns as POSIXct initially but this works)
We can use seq between the two columns and create a list with complete 15 minute intervals for each Beginning - Endand then use rep based on their length to get the value, i.e.
l1 <- Map(function(x, y)seq(x, y, by = '15 mins'), testdf$BeginTime, testdf$EndTime)
data.frame(Time = do.call(c, l1), value = rep(testdf$Value, lengths(l1)))
which gives,
Time value
1 2019-01-03 13:45:00 41
2 2019-01-03 14:00:00 41
3 2019-01-03 14:15:00 41
4 2019-01-03 14:30:00 41
5 2019-01-03 14:45:00 41
6 2019-01-03 15:00:00 41
7 2019-01-03 15:15:00 41
8 2019-01-03 15:30:00 41
9 2019-01-03 13:30:00 20
10 2019-01-03 13:45:00 20
11 2019-01-03 14:00:00 20
12 2019-01-03 14:15:00 20
13 2019-01-03 14:30:00 20
14 2019-01-03 16:45:00 23
15 2019-01-03 17:00:00 23
Using the tidyverse
testdf <- data.frame(c("2019-01-03 13:45:00", "2019-01-03 13:30:00", "2019-01-03 16:45:00"),
c("2019-01-03 15:30:00", "2019-01-03 14:30:00", "2019-01-03 17:00:00"),
c(41,20,23))
colnames(testdf) <-c("BeginTime", "EndTime", "Value")
testdf$BeginTime <- as.POSIXct(testdf$BeginTime)
testdf$EndTime <- as.POSIXct(testdf$EndTime)
library(tidyverse)
library(lubridate)
#>
#> Attaching package: 'lubridate'
#> The following object is masked from 'package:base':
#>
#> date
testdf %>%
mutate(periods = map2(BeginTime,EndTime,seq,by = '15 mins')) %>%
unnest(periods)
#> # A tibble: 15 x 4
#> BeginTime EndTime Value periods
#> <dttm> <dttm> <dbl> <dttm>
#> 1 2019-01-03 13:45:00 2019-01-03 15:30:00 41 2019-01-03 13:45:00
#> 2 2019-01-03 13:45:00 2019-01-03 15:30:00 41 2019-01-03 14:00:00
#> 3 2019-01-03 13:45:00 2019-01-03 15:30:00 41 2019-01-03 14:15:00
#> 4 2019-01-03 13:45:00 2019-01-03 15:30:00 41 2019-01-03 14:30:00
#> 5 2019-01-03 13:45:00 2019-01-03 15:30:00 41 2019-01-03 14:45:00
#> 6 2019-01-03 13:45:00 2019-01-03 15:30:00 41 2019-01-03 15:00:00
#> 7 2019-01-03 13:45:00 2019-01-03 15:30:00 41 2019-01-03 15:15:00
#> 8 2019-01-03 13:45:00 2019-01-03 15:30:00 41 2019-01-03 15:30:00
#> 9 2019-01-03 13:30:00 2019-01-03 14:30:00 20 2019-01-03 13:30:00
#> 10 2019-01-03 13:30:00 2019-01-03 14:30:00 20 2019-01-03 13:45:00
#> 11 2019-01-03 13:30:00 2019-01-03 14:30:00 20 2019-01-03 14:00:00
#> 12 2019-01-03 13:30:00 2019-01-03 14:30:00 20 2019-01-03 14:15:00
#> 13 2019-01-03 13:30:00 2019-01-03 14:30:00 20 2019-01-03 14:30:00
#> 14 2019-01-03 16:45:00 2019-01-03 17:00:00 23 2019-01-03 16:45:00
#> 15 2019-01-03 16:45:00 2019-01-03 17:00:00 23 2019-01-03 17:00:00
Created on 2020-01-07 by the reprex package (v0.3.0)
I have a large data set with individual columns for event times and dates. I ended up creating a master dttm object with both the times and dates together, but have had trouble when I try to filter based on the date. Here is a sample data set that reflects my own:
library(tidyverse)
d<- structure(list(date = structure(c(1530921600, 1531008000,
1530403200, 1530489600, 1530576000, 1530489600, 1530576000, 1531008000,
1530921600, 1530662400, 1530748800, 1531180800, 1530748800, 1531526400,
1531526400, 1532044800, 1532131200, 1531180800, 1531353600, 1531353600
), class = c("POSIXct", "POSIXt"), tzone = "UTC"), date_time = structure(c(1531019100,
1531117500, 1530440640, 1530562440, 1530633240, 1530571920, 1530648900,
1531037100, 1531010460, 1530717240, 1530808200, 1531237020, 1530813000,
1531614060, 1531637640, 1532104320, 1532195220, 1531290120, 1531434300,
1531409280), class = c("POSIXct", "POSIXt"), tzone = "")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -20L))
Here is the how the data look:
# A tibble: 20 x 2
date date_time
<dttm> <dttm>
1 2018-07-07 00:00:00 2018-07-07 20:05:00
2 2018-07-08 00:00:00 2018-07-08 23:25:00
3 2018-07-01 00:00:00 2018-07-01 03:24:00
4 2018-07-02 00:00:00 2018-07-02 13:14:00
5 2018-07-03 00:00:00 2018-07-03 08:54:00
6 2018-07-02 00:00:00 2018-07-02 15:52:00
7 2018-07-03 00:00:00 2018-07-03 13:15:00
8 2018-07-08 00:00:00 2018-07-08 01:05:00
9 2018-07-07 00:00:00 2018-07-07 17:41:00
10 2018-07-04 00:00:00 2018-07-04 08:14:00
11 2018-07-05 00:00:00 2018-07-05 09:30:00
12 2018-07-10 00:00:00 2018-07-10 08:37:00
13 2018-07-05 00:00:00 2018-07-05 10:50:00
14 2018-07-14 00:00:00 2018-07-14 17:21:00
15 2018-07-14 00:00:00 2018-07-14 23:54:00
16 2018-07-20 00:00:00 2018-07-20 09:32:00
17 2018-07-21 00:00:00 2018-07-21 10:47:00
18 2018-07-10 00:00:00 2018-07-10 23:22:00
19 2018-07-12 00:00:00 2018-07-12 15:25:00
20 2018-07-12 00:00:00 2018-07-12 08:28:00
You can see that all of the dates match across columns; the only difference is the presence of time information. But, when I convert both columns to the date class using as.Date...
d$date<- as.Date(d$date)
d$date_time<- as.Date(d$date_time)
# A tibble: 20 x 2
date date_time
<date> <date>
1 2018-07-07 2018-07-08
2 2018-07-08 2018-07-09
3 2018-07-01 2018-07-01
4 2018-07-02 2018-07-02
5 2018-07-03 2018-07-03
6 2018-07-02 2018-07-02
7 2018-07-03 2018-07-03
8 2018-07-08 2018-07-08
9 2018-07-07 2018-07-08
10 2018-07-04 2018-07-04
11 2018-07-05 2018-07-05
12 2018-07-10 2018-07-10
13 2018-07-05 2018-07-05
14 2018-07-14 2018-07-15
15 2018-07-14 2018-07-15
16 2018-07-20 2018-07-20
17 2018-07-21 2018-07-21
18 2018-07-10 2018-07-11
19 2018-07-12 2018-07-12
20 2018-07-12 2018-07-12
... several of the dates have been rounded up for the date_time column (rows 1, 2, 9, 14, 15, and 18). But, when I use lubridate::as_date to make the conversion...
# A tibble: 20 x 2
date date_time
<date> <date>
1 2018-07-07 2018-07-07
2 2018-07-08 2018-07-08
3 2018-07-01 2018-07-01
4 2018-07-02 2018-07-02
5 2018-07-03 2018-07-03
6 2018-07-02 2018-07-02
7 2018-07-03 2018-07-03
8 2018-07-08 2018-07-08
9 2018-07-07 2018-07-07
10 2018-07-04 2018-07-04
11 2018-07-05 2018-07-05
12 2018-07-10 2018-07-10
13 2018-07-05 2018-07-05
14 2018-07-14 2018-07-14
15 2018-07-14 2018-07-14
16 2018-07-20 2018-07-20
17 2018-07-21 2018-07-21
18 2018-07-10 2018-07-10
19 2018-07-12 2018-07-12
20 2018-07-12 2018-07-12
... the dates match perfectly across columns. I've tried reading the documentation but I can't seem to figure out why as.Date is working differently than lubridate::as_date. In fact, as.Date seems to be producing incorrect conversions in several cases.
Does anybody know what's going on?
In d$date the timezone is UTC while in d$date_time timezone has been defaulted to your default timezone. I am in EDT so here is mine:
> d$date_time
[1] "2018-07-07 23:05:00 EDT" "2018-07-09 02:25:00 EDT" "2018-07-01 06:24:00 EDT"
[4] "2018-07-02 16:14:00 EDT" "2018-07-03 11:54:00 EDT" "2018-07-02 18:52:00 EDT"
[7] "2018-07-03 16:15:00 EDT" "2018-07-08 04:05:00 EDT" "2018-07-07 20:41:00 EDT"
[10] "2018-07-04 11:14:00 EDT" "2018-07-05 12:30:00 EDT" "2018-07-10 11:37:00 EDT"
[13] "2018-07-05 13:50:00 EDT" "2018-07-14 20:21:00 EDT" "2018-07-15 02:54:00 EDT"
[16] "2018-07-20 12:32:00 EDT" "2018-07-21 13:47:00 EDT" "2018-07-11 02:22:00 EDT"
[19] "2018-07-12 18:25:00 EDT" "2018-07-12 11:28:00 EDT"
When you run as.Date() it will by default convert to UTC unless you specify a timezone. UTC is 4 hours ahead of EDT, thus days where the time is after 8pm will be converted to the next day, which you can see below.
> as.Date(d$date_time)
[1] "2018-07-08" "2018-07-09" "2018-07-01" "2018-07-02" "2018-07-03" "2018-07-02" "2018-07-03"
[8] "2018-07-08" "2018-07-08" "2018-07-04" "2018-07-05" "2018-07-10" "2018-07-05" "2018-07-15"
[15] "2018-07-15" "2018-07-20" "2018-07-21" "2018-07-11" "2018-07-12" "2018-07-12"
Lubridate as_date() specifically addresses this issue and even provides examples in its documentation.
as_date() ignores the timezone attribute, resulting in a more
intuitive conversion (see examples)
That is why you see the difference.
I am trying to combine dates and times. These are from a file when imported, looks like this:
library(tidyverse)
library(lubridate)
bookings <- structure(list(booking_date = structure(c(1549670400, 1550275200,
1550880000, 1551484800, 1552089600, 1552694400), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), start_time = structure(c(-2209043700,
-2209043700, -2209043700, -2209043700, -2209043700, -2209043700
), class = c("POSIXct", "POSIXt"), tzone = "UTC")), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
Which looks like this:
# A tibble: 6 x 2
booking_date start_time
<dttm> <dttm>
1 2019-02-09 00:00:00 1899-12-31 08:45:00
2 2019-02-16 00:00:00 1899-12-31 08:45:00
3 2019-02-23 00:00:00 1899-12-31 08:45:00
4 2019-03-02 00:00:00 1899-12-31 08:45:00
5 2019-03-09 00:00:00 1899-12-31 08:45:00
6 2019-03-16 00:00:00 1899-12-31 08:45:00
Obviously the date in the start_time column is wrong. It should be combined with the booking date, so that the first row should read 2019-02-09 08:45:00.
What would the best way of doing that be? I have tried this (based on this other answer), which doesn't really work in my situation.
bookings %>%
select(booking_date, start_time) %>%
mutate(time_2 = as.character(start_time)) %>%
mutate(time_3 = str_sub(time_2, -8, -1)) %>%
mutate(booking_start = dmy(paste(booking_date, time_3)))
Thanks.
If you want to get date for start_time from booking_date a base R approach would be to paste "Date" part from booking_date and "time" part from start_time and convert them to POSIXct.
bookings$start_time <- as.POSIXct(paste(as.Date(bookings$booking_date),
format(bookings$start_time, "%T")))
bookings
# A tibble: 6 x 2
# booking_date start_time
# <dttm> <dttm>
#1 2019-02-09 00:00:00 2019-02-09 08:45:00
#2 2019-02-16 00:00:00 2019-02-16 08:45:00
#3 2019-02-23 00:00:00 2019-02-23 08:45:00
#4 2019-03-02 00:00:00 2019-03-02 08:45:00
#5 2019-03-09 00:00:00 2019-03-09 08:45:00
#6 2019-03-16 00:00:00 2019-03-16 08:45:00
If you want to use it in pipes you can do
library(dplyr)
bookings %>%
mutate(start_time = as.POSIXct(paste(as.Date(booking_date),
format(start_time, "%T"))))
We can also do this with lubridate::date.
date() <- lets you set the date component of a date/time object:
# Set the date component of start_time to be the date component of booking_date
date(bookings$start_time) <- bookings$booking_date
bookings
# A tibble: 6 x 2
booking_date start_time
<dttm> <dttm>
1 2019-02-09 00:00:00 2019-02-09 08:45:00
2 2019-02-16 00:00:00 2019-02-16 08:45:00
3 2019-02-23 00:00:00 2019-02-23 08:45:00
4 2019-03-02 00:00:00 2019-03-02 08:45:00
5 2019-03-09 00:00:00 2019-03-09 08:45:00
6 2019-03-16 00:00:00 2019-03-16 08:45:00
Since it uses assignment (<-), you can't use this first method as part of a pipe. What does work in a pipe, is the update.POSIXt method (see ?DateTimeUpdate), which lets you update the date components of a date, though you have to specify each part of the components specifically:
library(lubridate)
bookings %>%
mutate(date_time = update(start_time,
year = year(booking_date),
month = month(booking_date),
day = day(booking_date)))
booking_date start_time date_time
<dttm> <dttm> <dttm>
1 2019-02-09 00:00:00 1899-12-31 08:45:00 2019-02-09 08:45:00
2 2019-02-16 00:00:00 1899-12-31 08:45:00 2019-02-16 08:45:00
3 2019-02-23 00:00:00 1899-12-31 08:45:00 2019-02-23 08:45:00
4 2019-03-02 00:00:00 1899-12-31 08:45:00 2019-03-02 08:45:00
5 2019-03-09 00:00:00 1899-12-31 08:45:00 2019-03-09 08:45:00
6 2019-03-16 00:00:00 1899-12-31 08:45:00 2019-03-16 08:45:00
I have a dataframe where I splitted the datetime column by date and time (two columns). However, when I group by time it gives me duplicates in time. So, to analyze it I used table() on time column, and it gave me duplicates also. This is a sample of it:
> table(df$time)
00:00:00 00:00:00 00:15:00 00:15:00 00:30:00 00:30:00
2211 1047 2211 1047 2211 1047
As you may see, when I splitted one of the "unique" values kept a " " inside. Is there a easy way to solve this?
PS: The datatype of the time column is character.
EDIT: Code added
df$datetime <- as.character.Date(df$datetime)
x <- colsplit(df$datetime, ' ', names = c('Date','Time'))
df <- cbind(df, x)
There are a number of approaches. One of them is to use appropriate functions to extract Dates and Times from Datetime column:
df <- data.frame(datetime = seq(
from=as.POSIXct("2018-5-15 0:00", tz="UTC"),
to=as.POSIXct("2018-5-16 24:00", tz="UTC"),
by="30 min") )
head(df$datetime)
#[1] "2018-05-15 00:00:00 UTC" "2018-05-15 00:30:00 UTC" "2018-05-15 01:00:00 UTC" "2018-05-15 01:30:00 UTC"
#[5] "2018-05-15 02:00:00 UTC" "2018-05-15 02:30:00 UTC"
df$Date <- as.Date(df$datetime)
df$Time <- format(df$datetime,"%H:%M:%S")
head(df)
# datetime Date Time
# 1 2018-05-15 00:00:00 2018-05-15 00:00:00
# 2 2018-05-15 00:30:00 2018-05-15 00:30:00
# 3 2018-05-15 01:00:00 2018-05-15 01:00:00
# 4 2018-05-15 01:30:00 2018-05-15 01:30:00
# 5 2018-05-15 02:00:00 2018-05-15 02:00:00
# 6 2018-05-15 02:30:00 2018-05-15 02:30:00
table(df$Time)
#00:00:00 00:30:00 01:00:00 01:30:00 02:00:00 02:30:00 03:00:00 03:30:00 04:00:00 04:30:00 05:00:00 05:30:00
#3 2 2 2 2 2 2 2 2 2 2 2
#06:00:00 06:30:00 07:00:00 07:30:00 08:00:00 08:30:00 09:00:00 09:30:00 10:00:00 10:30:00 11:00:00 11:30:00
#2 2 2 2 2 2 2 2 2 2 2 2
#12:00:00 12:30:00 13:00:00 13:30:00 14:00:00 14:30:00 15:00:00 15:30:00 16:00:00 16:30:00 17:00:00 17:30:00
#2 2 2 2 2 2 2 2 2 2 2 2
#18:00:00 18:30:00 19:00:00 19:30:00 20:00:00 20:30:00 21:00:00 21:30:00 22:00:00 22:30:00 23:00:00 23:30:00
#2 2 2 2 2 2 2 2 2 2 2 2
#If the data were given as character strings and contain extra spaces the above approach will still work
df <- data.frame(datetime=c("2018-05-15 00:00:00","2018-05-15 00:30:00",
"2018-05-15 01:00:00", "2018-05-15 02:00:00",
"2018-05-15 00:00:00","2018-05-15 00:30:00"),
stringsAsFactors=FALSE)
df$Date <- as.Date(df$datetime)
df$Time <- format(as.POSIXct(df$datetime, tz="UTC"),"%H:%M:%S")
head(df)
# datetime Date Time
# 1 2018-05-15 00:00:00 2018-05-15 00:00:00
# 2 2018-05-15 00:30:00 2018-05-15 00:30:00
# 3 2018-05-15 01:00:00 2018-05-15 01:00:00
# 4 2018-05-15 02:00:00 2018-05-15 02:00:00
# 5 2018-05-15 00:00:00 2018-05-15 00:00:00
# 6 2018-05-15 00:30:00 2018-05-15 00:30:00
table(df$Time)
#00:00:00 00:30:00 01:00:00 02:00:00
# 2 2 1 1
reshape2::colsplit accepts regular expressions, so you could split on '\s+' which matches 1 or more whitespace characters.
You can find out more about regular expressions in R using ?base::regex. The syntax is generally constant between languages, so you can use pretty much any regex tutorial. Take a look at https://regex101.com/. This site evaluates your regular expressions in real time and shows you exactly what each part is matching. It is extremely helpful!
Keep in mind that in R, as compared to most other languages, you must double the number of backslashes \. So \s (to match 1 whitespace character) must be written as \\s in R.
This question already has answers here:
How do I clear an NA flag for a posix value?
(3 answers)
Closed 5 years ago.
I have a large dataset (21683 records) and I've managed to combine date and time to datetime in a correct way using asPOSIXct. Nevertheless, this did not work for 6 records (17463:17468). This is the dataset I'm using:
> head(solar.angle)
Date Time sol.elev.angle ID Datetime
1 2016-11-24 15:00:00 41.32397 1 2016-11-24 15:00:00
2 2016-11-24 15:10:00 39.11225 2 2016-11-24 15:10:00
3 2016-11-24 15:20:00 36.88180 3 2016-11-24 15:20:00
4 2016-11-24 15:30:00 34.63507 4 2016-11-24 15:30:00
5 2016-11-24 15:40:00 32.37418 5 2016-11-24 15:40:00
6 2016-11-24 15:50:00 30.10096 6 2016-11-24 15:50:00
> solar.angle[17460:17470,]
Date Time sol.elev.angle ID Datetime
17488 2017-03-26 01:30:00 -72.01821 17460 2017-03-26 01:30:00
17489 2017-03-26 01:40:00 -69.53832 17461 2017-03-26 01:40:00
17490 2017-03-26 01:50:00 -67.05409 17462 2017-03-26 01:50:00
17491 2017-03-26 02:00:00 -64.56682 17463 <NA>
17492 2017-03-26 02:10:00 -62.07730 17464 <NA>
17493 2017-03-26 02:20:00 -59.58609 17465 <NA>
17494 2017-03-26 02:30:00 -57.09359 17466 <NA>
17495 2017-03-26 02:40:00 -54.60006 17467 <NA>
17496 2017-03-26 02:50:00 -52.10572 17468 <NA>
17497 2017-03-26 03:00:00 -49.61071 17469 2017-03-26 03:00:00
17498 2017-03-26 03:10:00 -47.11515 17470 2017-03-26 03:10:00
This is the code I'm using:
solar.angle$Datetime <- as.POSIXct(paste(solar.angle$Date,solar.angle$Time), format="%Y-%m-%d %H:%M:%S")
I've already tried to fill them in manually but this did not make any difference:
> solar.angle$Datetime[17463] <- as.POSIXct('2017-03-26 02:00:00', format = "%Y-%m-%d %H:%M:%S")
> solar.angle$Datetime[17463]
[1] NA
Any help will be appreciated!
The problem here is that this is the time you switch to summer time, so you need to specify the time zone, otherwise there is ambiguity.
If you specify a time zone, it will work:
as.POSIXct('2017-03-26 02:00:00', format = "%Y-%m-%d %H:%M:%S", tz = "GMT")
Which returns:
"2017-03-26 02:00:00 GMT"
You can check ?timezones for more information.