Assign date format with as.POSIXct

0

Please help me understand the function as.POSIXct

I have a meteorology weatherlink database and I can not assign a date and time format to the date column

  

R version 3.3.1 (2016-06-21) Platform: x86_64-w64-mingw32 / x64 (64-bit)   Running under: Windows> = 8 x64 (build 9200)

meteo$date <- as.POSIXct(strftime(meteo$date, format = "%d/%m/%Y %H:%M"))
  

Error in as.POSIXlt.character (x, tz, ...): character string is not   in a standard unambiguous format

    
asked by Lady M 19.09.2017 в 20:36
source

1 answer

0

Depends on how date is originally defined.

If it's like text, like in the example below, you do not need strftime ; the conversion can be direct:

meteo=data.frame(date=c("01/02/2010 10:20", "03/02/2010 15:20", "07/03/2010 01:20", "01/04/2011 12:20"),stringsAsFactors = F)
meteo$date1 <- as.POSIXct(meteo$date, format = "%d/%m/%Y %H:%M")

> meteo
              date               date1
1 01/02/2010 10:20 2010-02-01 10:20:00
2 03/02/2010 15:20 2010-02-03 15:20:00
3 07/03/2010 01:20 2010-03-07 01:20:00
4 01/04/2011 12:20 2011-04-01 12:20:00
    
answered by 05.10.2017 в 19:04