posixct

Weird POSIXct error

久未见 提交于 2021-01-28 04:26:41
问题 For some reason, as.POSIXct interprets "2013-03-10 02:00:00.000" different from other valid datetimes in that format. > as.POSIXct("2013-03-10 01:00:00.000") #Different time, same date [1] "2013-03-10 01:00:00 PST" > as.POSIXct("2013-03-11 02:00:00.000") #Same time, different date [1] "2013-03-11 02:00:00 PDT" > as.POSIXct("2013-03-10 02:00:00.000") [1] "2013-03-10 PST" I'm using the package RODBC to read this from a database, and it automatically converts this entire column of datetimes into

How to create a matrix of POSIXct

半腔热情 提交于 2021-01-28 03:23:58
问题 When I create a matrix given POSIXct vector in R 3.1.2 , the entries of the matrix are numeric instead of POSIXct: x <- as.POSIXct("2012-02-25 19:00:00") x attributes(x) m <- matrix(x, nrow=2, ncol=3) m attributes(m) What is the best way to create a matrix of POSIXct values? 回答1: I don't think I've ever seen someone create a matrix of POSIXct values before, although it's not difficult to imagine use-cases for such an object. R doesn't seem to support this type of object very well. The S3

Converting time format to numeric with R

℡╲_俬逩灬. 提交于 2021-01-21 07:42:09
问题 In most cases,we convert numeric time to posixct format using R. However, sometimes, we want to compare which time point is earlier, then we would prefer the numeric time format. Thus, it's quite practical question to convert time format to numeric. For example,I have the data format like "2001-03-13 10:31:00", begin <- "2001-03-13 10:31:00" Using R, I want to figure out how to covert it into a numeric, e.g. the Julian time, something like the passing seconds between 1970-01-01 00:00:00 and

merge.zoo removes time zone

廉价感情. 提交于 2020-12-12 10:52:09
问题 The result of merge.zoo does not have the same time zone as its input. Consider the following example library(zoo) zoo_a=zoo(data.frame(a=1:5), seq(as.POSIXct("2014-01-01 00:00:01",tz="UTC"), as.POSIXct("2014-01-01 00:00:05",tz="UTC"), by=1) ) zoo_b=zoo(data.frame(a=1:4), seq(as.POSIXct("2014-01-01 00:00:01",tz="UTC"), as.POSIXct("2014-01-01 00:00:05",tz="UTC"), by=1) ) zoo_merged=merge(zoo_a,zoo_b) time(zoo_merged)[1] #2013-12-31 19:00:01 EST time(zoo_a)[1] #2014-01-01 00:00:01 UTC time(zoo

Splitting multiple date and time variables & computing time average in R

北城以北 提交于 2020-08-09 07:23:19
问题 I have the following dataset wherein, I have the person's ID, district and sub-district they live in along with the last date/time on which they uploaded data to the server. The variables "last_down_" contain the last date/time on which a person the uploaded data and are named in such a way that they show the date on which I had downloaded the data on the same. For example, "last_upload_2020-06-12" would mean I downloaded the data from the server on 12th June. For the below dataset, I would

Unexpected date when converting POSIXct date-time to Date - can timezone fix it?

徘徊边缘 提交于 2020-07-09 11:52:31
问题 When I try to coerce a POSIXct date-time to a Date using as.Date , it seems to return wrong date. I suspect it has got something to do with the time zone. I tried the tz argument in as.Date , but it didn't give the expected date. # POSIXct returns day of month 24 data$Time[3] # [1] "2020-03-24 00:02:00 IST" class(data$Time[3]) # [1] "POSIXct" "POSIXt" # coerce to Date, returns 23 as.Date(data$Time[3]) # [1] "2020-03-23" # try the time zone argument, without luck as.Date(data$Time[3], tz =

Parse ISO 8601 combined date and time YYYY-MM-DDTHH-MM-SSZ

倾然丶 夕夏残阳落幕 提交于 2020-07-03 13:04:09
问题 I have a large dataframe with time stamps that look like this: "2019-05-15T01:42:15.072Z" It resembles a ISO 8601 combined date and time representation. How can I parse this string into a real date-time format? The characters ( T and Z ) inside the data seems to make it difficult. 回答1: You can simply parse the timestamp by specifying the format in as.POSIXct (or strptime ) as.POSIXct("2019-05-15T01:42:15.072Z", format = "%Y-%m-%dT%H:%M:%OSZ") #[1] "2019-05-15 01:42:15 AEST" Explanation: %Y ,