R as.POSIXct () discards hours and seconds

I am experimenting with R to analyze some measurement data. I have a .csv file containing over 2 million dimension lines. Here is an example:

2014-10-22 21:07:03+00:00,7432442.0
2014-10-22 21:07:21+00:00,7432443.0
2014-10-22 21:07:39+00:00,7432444.0
2014-10-22 21:07:57+00:00,7432445.0
2014-10-22 21:08:15+00:00,7432446.0
2014-10-22 21:08:33+00:00,7432447.0
2014-10-22 21:08:52+00:00,7432448.0
2014-10-22 21:09:10+00:00,7432449.0
2014-10-22 21:09:28+00:00,7432450.0

After reading in the file, I want the conversion time to be correct using as.POSIXct(). For small files, this works fine, but for large files this is not.

I made an example by reading a large file, making a copy of a small part and then decoupling as.POSIXct()in the right column. I included the image of the file. As you can see, applying it to temp-variable, it corrects the number of hours, minutes and seconds. However, applying it to the entire file only the date is saved. (it also takes a lot of time (more than 2 minutes))

POSIXct () error

? , .

Edit

Windows 7 R 3.1.3, . Ubuntu 14.01, R 3.0.2, . , Windows (3.2.0), , .

+3
3

.
:

  • datetime

library(data.table)
data <- fread("C:/RData/house2_electricity_main.csv")
data[, V1 := as.POSIXct(V1)]

fasttime::fastPOSIXct as.POSIXct, .

, POSIXct, , . year, month, mday...

data[, .SD, by = .(year(V1),month(V1),mday(V1))]
+3

, , - . :

  library(lubridate)
  dates <- as.character(now() + minutes(1:5))
  dates <- c(dates,"2015-05-10")
  as.POSIXct(dates[1:5])
  as.POSIXct(dates)

dates, 6 . ( ), . POSIXct, , , .

, , , , . , , , .

, :

data <- read.csv("C:/RData/house2_electricity_Main.csv",header=FALSE,stringsAsFactors=FALSE)

, , POSIXct:

data$V1 <- ifelse(nchar(data$V1) > 11,data$V1, paste0(data$V1,"00:00:00"))
data$V1 <- as.POSIXct(data$V1)

. , , , - .

+7

as.POSIXlt(X) hour:minute:second, X POSIXct, tzone="UTC".

as.POSIXlt(X, tz="UTC") hour:minute:second.

+2

Source: https://habr.com/ru/post/1648561/


All Articles