Questions tagged [posixct]

In the R language, the classes "POSIXct" and "POSIXlt" are representing calendar dates and times (to the nearest second).

The classes POSIXct and POSIXlt are representing calendar dates and times in R.

The class POSIXct represents the (signed) number of seconds since the beginning of 1970 (in the UTC timezone) as a numeric vector.

Class POSIXlt is a named list of vectors representing

  • sec: seconds (0-61)
  • min: minutes (0-59)
  • hour: hours (0-23)
  • mday: day of the month (1-31)
  • mon: months after the first of the year (0-11)
  • year: years since 1900
  • wday: day of the week, starting on Sunday (0-6)
  • yday: day of the year (0-365)
  • isdst: Daylight Savings Time flag. Positive if in force, zero if not, negative if unknown.

POSIXct is more convenient for including in data frames, and POSIXlt is closer to human-readable forms. A virtual class POSIXt exists from which both of the classes inherit.

References:

1056 questions
5
votes
3 answers

lubridate errors in R

I am using the following code to give me the day of the week from a date (in the form dd/mm/yyyy). Edit: I have uploaded a more relvant dataset. df <- structure(list(Date = c("18/01/2013", "18/01/2013", "18/01/2013", …
KT_1
  • 8,194
  • 15
  • 56
  • 68
5
votes
1 answer

Round a POSIX date and time (posixct) to a date relative to a timezone

I want to round a POSIXct down to the day, relative to a specific timezone. If I try round(as.POSIXct("2013-03-05 23:00:00 EST"), "day") It returns 2013-03-06 Which makes sense, in that when it's 23:00:00 EST on 2013-03-05 in EST5EDT, it's already…
loseeka
  • 117
  • 1
  • 9
5
votes
4 answers

Convert Date to year month representation

I have a Date, and am interested in representing it as an integer of yyyymm form. Currently, I do: get_year_month <- function(d) { return(as.integer(format(d, "%Y%m")))} mydate = seq.Date(from = as.Date("2012-01-01"), to = as.Date("5012-01-01"), by…
Alex
  • 19,533
  • 37
  • 126
  • 195
5
votes
3 answers

Cut a POSIXct by specific time for daily means

I am interested in calculating averages over specific time periods in a time series data set. Given a time series like this: dtm=as.POSIXct("2007-03-27 05:00", tz="GMT")+3600*(1:240) Count<-c(1:240) DF<-data.frame(dtm,Count) In the past I have…
Vinterwoo
  • 3,843
  • 6
  • 36
  • 55
5
votes
1 answer

How do POSIXct timezones work in R

I have a set of standard unix integer timestamps, all in UTC (GMT), that I'm feeding into R that I wish to plot. I've been using code of the form: d$date_time <- as.POSIXct(d$date_time,origin="1970-01-01",tz="GMT") to covert my column of standard…
Bryce Thomas
  • 10,479
  • 26
  • 77
  • 126
5
votes
2 answers

Round an POSIXct date up to the next day

I have a question similar to Round a POSIX date (POSIXct) with base R functionality, but I'm hoping to always round the date up to midnight the next day (00:00:00). Basically, I want a function equivalent to ceiling for POSIX-formatted dates. As…
Eli Sander
  • 1,228
  • 1
  • 13
  • 29
4
votes
2 answers

dplyr::if_else changes datetime (POSIXct) values

I'm working with a dataset that has a lot of timestamps. There are some invalid timestamps which I try to identify and set to NA. Because if_else() forces me to have the same data type in both arms, I'm using as.POSIXct(NA) to encode such missing…
4
votes
2 answers

Unexpected date when converting POSIXct date-time to Date - timezone issue?

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…
curious_cat
  • 805
  • 2
  • 9
  • 24
4
votes
1 answer

Wrapper to choose between scale_x_date and scale_x_datetime

Since scale_x_date is for "date" and scale_x_datetime is for "POSIXct", is it possible to have a wrapper to automatically decide which of the two to choose, since both even have the same function arguments. Similar to this but with its arguments…
Squeezie
  • 361
  • 2
  • 14
4
votes
3 answers

rbindlist: NA into date-time column

I am trying to build a function to insert a row of NAs into a data.table. I am using rbindlist in this way to accomplish it, where x is a data.table: rbindlist( list( x, as.list(rep(NA, ncol(x))) ) ) I am encountering an issue whereby…
moman822
  • 1,904
  • 3
  • 19
  • 33
4
votes
1 answer

POSIXct date objects getting converted by apply()

I am experiencing an issue working with POSIXct objects. With using functions that return POSIXct objects with sapply(), sapply() seems to automatically convert them to numeric. lapply() seems to maintain the POSIXct class, but when I unlist(), I…
Arthur
  • 1,248
  • 8
  • 14
4
votes
1 answer

POSIXct origin base type causes time zone differences

I've run into a problem with managing time zones with POSIXct in R. I have set the TZ option globally as "Europe/London" but since we have switched back to GMT have run as.POSIXct no longer converts the numeric vector back to the right time. Digging…
Glen Moutrie
  • 295
  • 3
  • 9
4
votes
1 answer

R round PosixCT variable in a data table

The following code creates a 10 row data table with one variable, timeStamp, in POSIXct format. library(data.table) dt <- data.table(timeStamp = seq( as.POSIXct("2017-07-01 14:51:50"), by=60, len=10)) I want to round timeStamp to the nearest…
JerryN
  • 2,356
  • 1
  • 15
  • 49
4
votes
1 answer

Warning on on POSIXlt(as.POSIXlt(x), ...)

when R was throwing warning messages on this command `setwd("~/Desktop/Project R") Warning message: In format.POSIXlt(as.POSIXlt(x), ...) : unknown timezone 'default/Asia/Kolkata'` So, I tried creating a date for this TZ by entering…
J.Pan
  • 51
  • 1
4
votes
1 answer

R Merging XTS time series causing duplicate time of day

I've never found an efficient way to solve a problem I've encountered every time I try to combine different sources of time series data. By different sources, I mean combining say a data source from the internet (yahoo stock prices) with say a local…
user1234440
  • 22,521
  • 18
  • 61
  • 103