-1

I have a dataset Peil_1 with column "timestamp" representing the time "value" was measured.

# A tibble: 175,350 x 5
   Timestamp                     Value `Quality Code` `Absolute Value` `AV Quality Code`
   <chr>                         <dbl>          <dbl>            <dbl>             <dbl>
 1 2014-11-01T00:00:00.000+01:00 0.712             10             12.4                10
 2 2014-11-01T00:15:00.000+01:00 0.712             10             12.4                10
 3 2014-11-01T00:30:00.000+01:00 0.712             10             12.4                10
 4 2014-11-01T00:45:00.000+01:00 0.712             10             12.4                10
 5 2014-11-01T01:00:00.000+01:00 0.712             10             12.4                10
 6 2014-11-01T01:15:00.000+01:00 0.712             10             12.4                10
 7 2014-11-01T01:30:00.000+01:00 0.712             10             12.4                10
 8 2014-11-01T01:45:00.000+01:00 0.713             10             12.4                10
 9 2014-11-01T02:00:00.000+01:00 0.713             10             12.4                10
10 2014-11-01T02:15:00.000+01:00 0.713             10             12.4                10
# ... with 175,340 more rows

I want to convert Peil_1$timestamp to a time or date format. I thought to use as.date, but I don't know how to handle the T00: 00: 00,000 + 1: 00 part

  • Hi, can you please post the output of `dput(head(Peil_1$Timestamp))` inside your question? In the meanwhile you can check [this similar question](https://stackoverflow.com/questions/58656245/how-can-i-rearrange-the-date-from-d-m-y-to-m-d-y-in-r/58656728#58656728) – Cettt Nov 01 '19 at 13:13
  • Try `lubridate::ymd_hms(Peil_1$timestamp)` – deepseefan Nov 01 '19 at 13:17

1 Answers1

0

Actually as.Date seems to work for me:

x <- "2014-11-01T00:00:00.000+01:00"
as.Date(x)

[1] "2014-11-01"

It appears that as.Date only checks if the format mask matches starting from the left of the text date, and ignores the rest. Hence, the following text timestamp can also be converted to a date:

x <- "2014-11-01 Jon Skeet"
as.Date(x)

[1] "2014-11-01"
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360