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
9
votes
4 answers

Parsing ISO8601 in R

Are there any existing implementations in R to parse ISO8601 strings into POSIXt objects? The ISO8601 spec allows date/times to be printed in a variety of (non-overlapping) formats, so one probably needs to do some regular expression magic to detect…
Jeroen Ooms
  • 31,998
  • 35
  • 134
  • 207
8
votes
2 answers

Error from ggplot2 plotting date data -- missing value where TRUE/FALSE needed

I'm trying to plot some grades I'm pulling from an external source. The date format comes in looking like this: 2011-08-23T17:07:05 So I parse it with strptime(date, "%FT%X") and get a POSIXlt. I end up with a complete data frame that looks like…
Dustin
  • 89,080
  • 21
  • 111
  • 133
8
votes
1 answer

How to get the first date from a vector?

I have a vector of POSIXct objects, I would like to determine the first and the last date/time value in the list. POSIXct_vector <- read.csv(file="data", as.is=TRUE) POSIXct_vector$DateTime <- as.POSIXct(POSIXct_vector) #returns…
klonq
  • 3,535
  • 4
  • 36
  • 58
8
votes
6 answers

R: Using dplyr to count number of occurence 1 hour ahead

was trying to figure a way to use dplyr to count the number of occurrences for each id at each time 1 hour ahead. Tried using a for loop but it doesn't give me the desired result. Went through stack and tried looking for various methods but to no…
8
votes
1 answer

Is there a fast parser for date

For datetimes fasttime provides very fast parsing to POSIXct library('fasttime') library('lubridate') library('microbenchmark') # parse character to POSIXct Sys.setenv(TZ='UTC') test <- rep('2011-04-02 11:01:00',1e4) microbenchmark( test1 <-…
statquant
  • 13,672
  • 21
  • 91
  • 162
8
votes
2 answers

How to convert Date or Datetime field when some parts are blank; na.omit fails

I have a data set that has dates and times for in and out. Each line is an in and out set, but some are blank. I can remove the blanks with na.omit and a nice read in (it was a csv, and na.strings=c("") works on the read.csv). Of course, because…
Rufus Shinra
  • 383
  • 1
  • 9
8
votes
1 answer

Converting chr "00:00:00" to date-time "00:00:00"

My question comes from this question. The question had the following character string. x <- "2007-02-01 00:00:00" y <- "02/01/2007 00:06:10" If you try to convert this string to date-class object, something funny happens. This is a sample from…
jazzurro
  • 23,179
  • 35
  • 66
  • 76
8
votes
2 answers

Is there a specific way to handle timestamp columns in R when pulling data using RPostgreSQL?

I'm trying to pull data from a PostgreSQL database and the results for a timestamp field are inconsistent. I'm not sure if I'm handling POSIXct results properly. Otherwise, I think I found a bug in the RPostgreSQL package. Here is the way to…
JAponte
  • 1,508
  • 1
  • 13
  • 21
8
votes
1 answer

Returning a vector of class POSIXct with vapply

I have list of dates having POSIXct class as follows (just a minimum working example): L <- list(as.POSIXct("2012-12-12 12:12:12"), as.POSIXct("2012-12-12 12:12:12")) I need to retrieve a vector of class POSIXct from it. This rules out lapply, and…
Dmitrii I.
  • 696
  • 7
  • 16
7
votes
1 answer

Using dplyr::if_else() in R to change the time zone of POSIXct timestamps based on value of another variable

I'm working with some timestamps in POSIXct format. Right now they are all showing up as being in the timezone "UTC", but in reality some are known to be in the "America/New_York" timezone. I'd like to correct the timestamps so that they all read as…
KTrooper
  • 495
  • 1
  • 4
  • 6
7
votes
2 answers

r, write_csv is changing all times/dates to UTC

I have found a very annoying problem that I want to share with the community. This is a question that I have found an acceptable solution for (detailed below), but I now have several follow-up questions. My knowledge of time stamps and POSIX…
Phil_T
  • 942
  • 9
  • 27
7
votes
1 answer

In R, why do I get one millisecond difference between POSIXct and POSIXlt?

This snippet options(digits.secs=3) s<-"12:00:00.188" fmt<-"%I:%M:%OS" print(strptime(s,fmt)) print(as.POSIXct(strptime(s,fmt))) gives this textual output: [1] "2017-09-12 00:00:00.188 CEST" [1] "2017-09-12 00:00:00.187 CEST" while I expect the…
Alessandro Jacopson
  • 18,047
  • 15
  • 98
  • 153
7
votes
1 answer

Plotting daytime (without date) in ggplot2

I want to scatterplot a numeric vector versus daytime (%H:%M) in ggplot2. I understand that as.POSIXct(dat$daytime, format = "%H:%M") is the way to go in terms of formatting my timedata, but the output vector will still include a date (today's…
7
votes
1 answer

Why is POSIXct converted to numeric when converting list to vector

I have a list redDressTweets of statuses. status is a class with a field created. I am trying to form a list of times in which tweets were posted. Here is how I'm trying to do it times <- unlist(lapply(redDressTweets, function(tweet) {tweet$created…
wlad
  • 2,073
  • 2
  • 18
  • 29
7
votes
0 answers

Bizzare as.POSIXct behavior for some time stamp with time part dropping

I was struggling that read.csv with colClasses containing POSIXct was rounding up entire timestamps column down to date dropping time part. I came across a similar question suggesting that some date I have may miss time part. That was not the case.…
mlt
  • 1,595
  • 2
  • 21
  • 52