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
3
votes
2 answers

Using an ifelse() statement for datetime observations within a given interval

I would like to assign a value to the df$lamp_intensity vector depending on a specific time interval within df$date. If a given observation is outside of this interval, I would like to assign an NA. Once I get this first bit of code working, I plan…
philiporlando
  • 941
  • 4
  • 19
  • 31
3
votes
0 answers

Why do I lose the change of timezone of a POSIXct object when exporting to xslx?

Why do I lose the change of timezone of a POSIXct object when exporting to xslx? data: t<- structure(list(created_at = structure(c(1502132771, 1502132774, 1502132827, 1502132855, 1502132877), class = c("POSIXct", "POSIXt"), tzone = "UTC")), class =…
zoowalk
  • 2,018
  • 20
  • 33
3
votes
1 answer

Dates, timezone and POSIXct

I just fread a large datafile, and the "DATE" column is stored as character like O5JAN2004, 06JAN2004.The time in this datafile is matched to NewYork time, and I live in Los Angeles. Then I use as.Date to convert character to date. t <-…
yuan yuan
  • 73
  • 1
  • 8
3
votes
2 answers

Openxlsx convertToDateTime omits time with big dataset

I am trying to use openxlsx to read large excel files with time series data. I found that convertToDateTime starts omitting the time if the numeric vector argument exceeds a certain amount of elements. My code looks like this: ts <-…
FlorianK
  • 71
  • 6
3
votes
2 answers

Map custom color gradient to POSIXct values

Data: df1 <- structure(list(Index = 1:11, Duration = structure(c(1487577655, 1487577670, 1487577675, 1487577680, 1487577685, 1487577680, 1487577700, 1487577705, 1487577695, 1487577700, 1487577680), class = c("POSIXct", "POSIXt"), tzone = "")),…
Mako212
  • 6,787
  • 1
  • 18
  • 37
3
votes
1 answer

How to properly combine POSIXct objects with NULL in R?

When using R's primitive c function, combining the current datetime with NULL gives: > class(c(NULL,Sys.time())) [1] "numeric" But when passing NULL last: > class(c(Sys.time(),NULL)) [1] "POSIXct" "POSIXt" Is this intended? The documentation for c…
ddisk
  • 310
  • 2
  • 7
3
votes
2 answers

How to properly handle timezone when passing POSIXct objects between R and Postgres DBMS?

I am struggling to understand what exactly happens behind the scenes when passing POSIXct objects between R and Postgres using RPostgreSQL. In the following example, I define two timestamp fields: one with a timezone the other one without. However,…
Mark Heckmann
  • 10,943
  • 4
  • 56
  • 88
3
votes
1 answer

scale_datetime shifts x axis

I am trying to plot a time series that has an x axis of class "POSIXct" using ggplot2, which is working up to a point. When I try to manipulate the x axis breaks and labels using scale_x_datetime it generates a one month shift in the x axis. Can…
Tim
  • 33
  • 3
3
votes
1 answer

How to correctly use as.POSIXct function inside a cat function

I would like to get a data format like "yyyy-mm-dd hh:mm:ss timezone" for Sys.time() as part of the "cat" function. When I use the two functions by themselves there is no problem but when I use the conversion function inside the cat function I…
mql4beginner
  • 2,193
  • 5
  • 34
  • 73
3
votes
2 answers

Use start and end time to extract values from separate dataframe

I have worked through a lot of issues in stats and database issues in R and am a new user, but I have not figured out loops and programming yet. I am stuck with this one and just can't figure it out. I have a dataframe that has a start date and an…
Bill Perry
  • 463
  • 1
  • 5
  • 13
3
votes
1 answer

How to parse date and time with milliseconds, spread across multiple columns?

I am having issues with incorporating milliseconds in formatting date and time which has milliseconds. Description: date format in csv is spread across first 3 columns 2014/12/22,14:48:51,800 as date, time and milliseconds , respectively. So, I…
3
votes
0 answers

Unusual error in seq.POSIXt

I was trying to create a sequence of dates using the following code: seq(from = as.POSIXct("2008-01-10 21:20:00 GMT", origin = "1970-01-01 00:00:00", format =…
Glen Moutrie
  • 295
  • 3
  • 9
3
votes
2 answers

R data.table interval

DT is data.table with POSIXct column 'date_and_time'. How do I use data.table syntax to add a 3 levels factor column indicating to which shift each 'date_and_time' instance belong? DT <- data.table(date_and_time = as.POSIXct( c("1997-07-01…
Amitai
  • 871
  • 1
  • 8
  • 21
3
votes
0 answers

Reading Excel date time data into R

I have a large data set in Excel (50k rows, 138 columns). 80 of the columns are date/time values which I want to use as POSIXct type in R. Option 1: Use XLConnect or xlsx with the colTypes parameter. Fails due to size of the file with heap size…
sch56
  • 361
  • 1
  • 11
3
votes
1 answer

R, problems plotting dates in Shiny and ggvis

I'm a bit new to Shiny and ggvis, and actually have a couple of problems here. First I have data in the format: Event.Hour Count Group 1 2015-10-08 00:00:00 1476 All 2 2015-10-08 01:00:00 22186 All 3 2015-10-08 02:00:00…
danh
  • 618
  • 3
  • 7