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
4
votes
1 answer

Force ggplot scales to start on e.g. 1st of year, 1st of month etc

I'm looking for a way to force the date labels on a ggplot to start at a (seemingly) logical time. I've had the problem a number of times but my current problem is I want the breaks to be on the 01/01/yyyy My data is a large dataset with POSIXct…
Sarah
  • 3,022
  • 1
  • 19
  • 40
4
votes
1 answer

Is there any faster alternative to POSIXct in R?

I am reading a CSV with fread (as it is quicker than read_csv method), timestamp column is taken as character type. I want to convert it to POSIXct with: as.POSIXct(strptime(rawTime, "%Y-%m-%d %H:%M:%OS")) But this POSIXct call is very slow. Is…
Devharsh Trivedi
  • 561
  • 8
  • 23
4
votes
1 answer

dplyr group_by throw error on variable not in the function

I am using R 3.4.0 and dplyr 0.5.0 (I also have tested using R 3.3.3 and I have the same error). I have been using this following type of code regularly in the past (even yesterday!) but for some reasons it creates an error today. For instance, I…
4
votes
2 answers

Round time by X hours in R?

While doing predicting modeling on timestamped data, I want to write a function in R (possibly using data.table) that rounds the date by X number of hours. E.g. rounding by 2 hours should give this: "2014-12-28 22:59:00 EDT" becomes "2014-12-28…
IVIM
  • 2,167
  • 1
  • 15
  • 41
4
votes
1 answer

Passing POSIXct object to function returns numeric vector

I'm trying to do some manipulation on the POSIXct vector, but when I pass it to a function, the vector changes into a numeric vector, instead of retaining POSIXct class, even when the function itself only returns the object: # Sample dates from…
kmo
  • 103
  • 7
4
votes
2 answers

How can I keep midnight (00:00h) using strptime() in R?

I have a dataframe, df, which has factor variable for date in the following format: 2015-12-15 10:00:00 2015-12-19 12:00:00 2015-12-20 20:00:00 It is hourly data. The problem arises when looking at midnight, 00:00:00, because it doesn't appear the…
adrian1121
  • 904
  • 2
  • 9
  • 21
4
votes
1 answer

How to format fractional seconds in POSIXct in r

I have read other questions regarding this topic but they do not seem to work on my dataset: Timestamp Bid.price Ask.price Bid.volume Ask.volume 20070313 07:01:04:762 11.14122 11.14478 4.539397 1.891416 20070313 07:01:07:608 …
Rime
  • 912
  • 2
  • 11
  • 39
4
votes
3 answers

How to get the beginning of the day in POSIXct

My day starts at 2016-03-02 00:00:00. Not 2016-03-02 00:00:01. How do I get the beginning of the day in POSIXct in local time? My confusing probably comes from the fact that R sees this as the end-date of 2016-03-01? Given that R uses an ISO…
Thorst
  • 1,590
  • 1
  • 21
  • 35
4
votes
1 answer

R POSIXct and as.Date

I have a date and time value which I'm using POSIXct to store in a variable. and when I use as.Date the date is different - why ? x<-as.POSIXct("2012-02-25 19:00:00") as.Date(x) [1] "2012-02-**26**" Why is it incrementing day by 1?
Sri
  • 1,130
  • 1
  • 15
  • 31
4
votes
2 answers

Decompose xts hourly time series

I want to decompose hourly time series with decompose, ets, or stl or whatever function. Here is an example code and its output: require(xts) require(forecast) time_index1 <- seq(from = as.POSIXct("2012-05-15 07:00"), to =…
Samy Geronymos
  • 395
  • 2
  • 5
  • 15
4
votes
3 answers

Trouble dealing with POSIXct timezones and truncating the time out of POSIXct objects

I have the following piece of R-code: formatString = "%Y-%m-%d %H:%M:%OS" x = as.POSIXct(strptime("2013-11-23 23:10:38.000000", formatString)) y = as.POSIXct(strptime("2015-07-17 01:43:38.000000", formatString)) I have the problem that when I do…
Fabian Werner
  • 957
  • 11
  • 19
4
votes
3 answers

R convert number into time

Someone gave me really bad data in Excel, where the date (such as July 1, 2015) is 20150701 and the time (such as 11:41:23) is 114123. There are over 50,000 rows of data and I need to convert these all into proper date and time objects. These aren't…
Zachary Weixelbaum
  • 904
  • 1
  • 11
  • 24
4
votes
1 answer

How to most efficiently convert a character string of "01 Jan 2014" to POSIXct i.e. "2014-01-01" yyyy-mm-dd

I already have a partial answer to the problem here, which I understand as far as it is explained: How to most efficiently restructure a character string for fasttime in data.table However, the task has been extended, and needs to deal with a…
DaveRGP
  • 1,430
  • 15
  • 34
4
votes
2 answers

Converting character to POSIXct in R loses time zone

I am trying to convert a character string into a POSIXct date format and running into a problem with the time zone information. The original character data looks like this: SD$BGN_DTTM [1] "1956-05-25 14:30:00 CST" "1956-06-05 16:30:00 CST"…
Jen H
  • 43
  • 4
4
votes
1 answer

differences between subsetting POSIXlt and POSIXct in R

DATA v1 <- c("2015-01-05 15:00:00", "2015-01-05 15:45:00", "2015-01-05 15:00:30") OPERATIONS v2 <- strptime(v1, '%Y-%m-%d %H:%M:%S') str(v2) POSIXlt[1:3], format: "2015-01-05 15:00:00" "2015-01-05 15:45:00" "2015-01-05 15:00:30" v3 <- v2[!v2$min] …
jpinelo
  • 1,414
  • 5
  • 16
  • 28