I try to match two files by using the time column in r. Therefore, I choose chron time to achieve this. But when I try to convert the 'Time' column to chron time, I got the warning message that 'In convert.dates(dates., format = format[[1]], origin. = origin.): 331 months out of range set to NA' my data are as follows,
Year Month Day Rain_mm Time chrontime
1 2019 1 1 0.6 01/01/2019 01:10:00 (01/01/19 01:10:00)
2 2019 1 2 0.0 02/01/2019 01:10:00 (02/01/19 01:10:00)
3 2019 1 3 0.0 03/01/2019 01:10:00 (03/01/19 01:10:00)
4 2019 1 4 0.0 04/01/2019 01:10:00 (04/01/19 01:10:00)
5 2019 1 5 0.0 05/01/2019 01:10:00 (05/01/19 01:10:00)
6 2019 1 6 0.0 06/01/2019 01:10:00 (06/01/19 01:10:00)
7 2019 1 7 3.4 07/01/2019 01:10:00 (07/01/19 01:10:00)
8 2019 1 8 5.8 08/01/2019 01:10:00 (08/01/19 01:10:00)
9 2019 1 9 0.4 09/01/2019 01:10:00 (09/01/19 01:10:00)
10 2019 1 10 0.0 10/01/2019 01:10:00 (10/01/19 01:10:00)
11 2019 1 11 0.2 11/01/2019 01:10:00 (11/01/19 01:10:00)
12 2019 1 12 2.8 12/01/2019 01:10:00 (12/01/19 01:10:00)
13 2019 1 13 2.6 13/01/2019 01:10:00 (NA NA)
14 2019 1 14 2.2 14/01/2019 01:10:00 (NA NA)
15 2019 1 15 3.2 15/01/2019 01:10:00 (NA NA)
16 2019 1 16 6.2 16/01/2019 01:10:00 (NA NA)
17 2019 1 17 12.6 17/01/2019 01:10:00 (NA NA)
18 2019 1 18 0.0 18/01/2019 01:10:00 (NA NA)
19 2019 1 19 0.0 19/01/2019 01:10:00 (NA NA)
20 2019 1 20 0.0 20/01/2019 01:10:00 (NA NA)
21 2019 1 21 7.4 21/01/2019 01:10:00 (NA NA)
22 2019 1 22 0.2 22/01/2019 01:10:00 (NA NA)
23 2019 1 23 0.0 23/01/2019 01:10:00 (NA NA)
24 2019 1 24 0.0 24/01/2019 01:10:00 (NA NA)
25 2019 1 25 0.0 25/01/2019 01:10:00 (NA NA)
26 2019 1 26 0.6 26/01/2019 01:10:00 (NA NA)
27 2019 1 27 7.6 27/01/2019 01:10:00 (NA NA)
28 2019 1 28 1.6 28/01/2019 01:10:00 (NA NA)
29 2019 1 29 0.0 29/01/2019 01:10:00 (NA NA)
30 2019 1 30 0.0 30/01/2019 01:10:00 (NA NA)
31 2019 1 31 0.0 31/01/2019 01:10:00 (NA NA)
32 2019 2 1 0.0 01/02/2019 01:10:00 (01/02/19 01:10:00)
33 2019 2 2 0.6 02/02/2019 01:10:00 (02/02/19 01:10:00)
34 2019 2 3 0.0 03/02/2019 01:10:00 (03/02/19 01:10:00)
35 2019 2 4 1.0 04/02/2019 01:10:00 (04/02/19 01:10:00)
36 2019 2 5 0.2 05/02/2019 01:10:00 (05/02/19 01:10:00)
37 2019 2 6 3.6 06/02/2019 01:10:00 (06/02/19 01:10:00)
38 2019 2 7 1.8 07/02/2019 01:10:00 (07/02/19 01:10:00)
39 2019 2 8 3.0 08/02/2019 01:10:00 (08/02/19 01:10:00)
40 2019 2 9 6.8 09/02/2019 01:10:00 (09/02/19 01:10:00)
41 2019 2 10 3.4 10/02/2019 01:10:00 (10/02/19 01:10:00)
42 2019 2 11 0.6 11/02/2019 01:10:00 (11/02/19 01:10:00)
43 2019 2 12 0.0 12/02/2019 01:10:00 (12/02/19 01:10:00)
44 2019 2 13 0.0 13/02/2019 01:10:00 (NA NA)
45 2019 2 14 0.0 14/02/2019 01:10:00 (NA NA)
46 2019 2 15 0.0 15/02/2019 01:10:00 (NA NA)
......
my codes are:
Dts <- with(DMIdata, paste(substring(Time, 1,2), substring(Time,4,5), substring(Time, 9, 10), sep='/'))
hrs <- with(DMIdata, substring(Time, 13, 20))
DMIdata$chrontime <- chron(Dts,hrs)
I was wondering why all the dates after the 13th are set to NA in the chronic transformation? And how to improve my codes to make it work?
Thanks for any help!
The issue with
substring
is that the order chron expects for Date to be certainformat
specified in the?chron
By default, if we look at the Usage, it is
mdy
while the OP's Dts are in d/m/y. We could specify the
format
heredata