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:

894 questions
11
votes
3 answers

05:00:00 - 28:59:59 time format

I have dataset where time.start vary from 5:00:00 to 28:59:59 (i.e. 01.01.2013 28:00:00 is actually 02.01.2013 04:00:00). Dates are in %d.%m.%Y format. Date Time.start 01.01.2013 22:13:07 01.01.2013 22:52:23 01.01.2013 …
BiXiC
  • 817
  • 2
  • 8
  • 26
10
votes
5 answers

How to avoid that anytime() "updates by reference"?

I want to convert a numeric variable to POSIXct using anytime. My issue is that anytime() converts the input variable as well - I want to keep it. Simple example: library(anytime) t_num <- 1529734500 anytime(t_num) # [1] "2018-06-23…
Henrik
  • 56,228
  • 12
  • 124
  • 139
9
votes
1 answer

How to calculate number of days between two dates in R

I'm trying to subtract two dates in R. These are the two dates via the structure command: str(standard_data_4testing$start_datetime) POSIXct[1:489124], format: "2016-02-01 00:38:49" "2016-02-01 07:48:53" "2016-02-01 08:32:08" "2016-02-01 11:21:13"…
Jazzmine
  • 1,605
  • 6
  • 31
  • 49
9
votes
2 answers

Get correct datetime from Oracle query via ROracle in R

I am using ROracle within R to access an Oracle database. I noticed that probably since the summer-time change, any DATE (datetime) Oracle column are now converted wrongly (I get an hour LESS in R than in the Oracle DB). From page 12 of the…
statquant
  • 12,389
  • 13
  • 75
  • 148
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
  • 28,942
  • 33
  • 116
  • 190
9
votes
2 answers

Unexpected output from all.equal.POSIXct

I'm getting unexpected output from the all.equal method in R, specifically the implementation for POSIXct, all.equal.POSIXct. t <- Sys.time() isTRUE(all.equal(t, t+1)) returns TRUE, and isTRUE(all.equal(t, t+1, scale = 1)) returns FALSE. However,…
Ash
  • 227
  • 2
  • 10
8
votes
4 answers

Converting time format to numeric with R

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.…
Frank Wang
  • 1,198
  • 3
  • 14
  • 33
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
  • 81,492
  • 18
  • 106
  • 131
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,332
  • 4
  • 31
  • 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
2 answers

R time_trans works with objects of class POSIXct

I have data with stock prices(data). Stock data I would like to visualize it. I first use ggplot R plotting to visualize the series. Date Closed 2010-07-19 0.0808 2010-07-20 0.7547 When I used below code my_date_format <-…
little girl
  • 235
  • 1
  • 3
  • 14
8
votes
6 answers

Determine season from Date using lubridate in R

I have a very big dataset with a DateTime Column containing POSIXct-Values. I need to determine the season (Winter - Summer) based on the DateTime column. I've created a function which works fine on a small dataset, but crashes when I use it on the…
Ratnanil
  • 1,316
  • 12
  • 29
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
  • 343
  • 1
  • 9
8
votes
2 answers

ifelse() stripping POSIXct attribute from vector of timestamps?

This is weird: R's ifelse() seems to do some (unwanted) casting: Lets say I have a vector of timestamps (possibly NA) and NA values should be treated differently than existing dates, for example, just ignored: formatString = "%Y-%m-%d…
Fabian Werner
  • 827
  • 6
  • 17
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.
  • 687
  • 7
  • 15
1 2
3
59 60