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
7
votes
5 answers

R: data.table. How to save dates properly with fwrite?

I have a dataset. I can choose to load it on R from a Stata file or from a SPSS file. In both cases it's loaded properly with the haven package. The dates are recognized properly. But when I save it to disk with data.table's fwrite…
skan
  • 7,423
  • 14
  • 59
  • 96
7
votes
1 answer

R shows NA although a value is present

I have two columns of PosixLT times with no NA values , yet NA values show up upon check > sum(is.na(check$start)) [1] 19 > sum(is.na(check$end)) [1] 23 The data is present in the cells, so why does this happen? I have heard that this can happen…
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
7
votes
1 answer

Add one year to a posix time

I have a date like "2016-01-01" (YYYY-MM-DD) and I'm using as.numeric(as.POSIXct(...)) to use it as an Integer. My question is, is there a way to add to this date a year, a month or a day ? I mean, if I add one year to 2016 it wont be the same as…
BobLeGob
  • 181
  • 1
  • 1
  • 5
7
votes
4 answers

R package constructing time objects from date and hour(integer)

I have data provided in the form of a date telling the day (format "YYYY-MM-DD", e.g. "2015-03-11" and the hours of the day numbered (0-23). What is the most convenient way to produce time objects of the form "2015-03-11" and hour = 0 -> …
Richi W
  • 3,534
  • 4
  • 20
  • 39
7
votes
1 answer

Using sapply on vector of POSIXct

I have what may be a very simple question. I want to process a column of POSIXct objects from a dataframe and generate a vector of datetime strings. I tried to use the following sapply call dt <- sapply(df$datetime, function(x)…
Chris
  • 3,109
  • 7
  • 29
  • 39
7
votes
1 answer

melt.data.frame() changes behavior how POSIXct columns are printed

Melting the dataframe t.wide changes how the column "time" (class POSIXct) is printed. t.wide <- data.frame(product=letters[1:5], result=c(2, 4, 0, 0, 1), t1=as.POSIXct("2014-05-26") + seq(0, 10800,…
Tobias
  • 422
  • 2
  • 6
7
votes
3 answers

How to prevent write.csv from changing POSIXct, dates and times class back to character/factors?

I have a .csv file with one field each for datetime, date and time. Originally they are all character fields and I have converted them accordingly. At the end of my code, if I do: str(data) I will get datetime: POSIXct date: Date time: Class…
7
votes
2 answers

Improve performance of data.table date+time pasting?

I am not sure that I can ask this question here, let me know if I should do it somewhere else. I have a data.table with 1e6 rows having this structure: V1 V2 V3 1: 03/09/2011 08:05:40 1145.0 2: 03/09/2011 08:06:01 1207.3 3:…
agstudy
  • 119,832
  • 17
  • 199
  • 261
7
votes
1 answer

How to convert specific time format to timestamp in R?

I am working on "Localization Data for Person Activity Data Set" dataset from UCI and in this data set there is a column of date and time(both in one column) with following format: 27.05.2009 14:03:25:777 27.05.2009 14:03:25:183 27.05.2009…
Soroosh
  • 477
  • 2
  • 7
  • 18
7
votes
1 answer

as.Date() does not respect POSIXct time zones

Okay so here is a subtle "quirk" in the r as.Date function converting from a POSIXct with a timezone, which I am wondering if it is a bug. > as.POSIXct("2013-03-29", tz = "Europe/London") [1] "2013-03-29 GMT" > as.Date(as.POSIXct("2013-03-29", tz =…
Thomas Browne
  • 23,824
  • 32
  • 78
  • 121
7
votes
4 answers

Accurately converting from character->POSIXct->character with sub millisecond datetimes

I have a character datetime column in a file. I load the file (into a data.table) and do things that require the column to be converted to POSIXct. I then need to write the POSIXct value back to file, but the datetime will not be the same (because…
statquant
  • 13,672
  • 21
  • 91
  • 162
7
votes
1 answer

time zones in POSIXct and xts, converting from GMT in R

I have a bunch of 1 minute returns in an xts object with the index being POSIXct and time zone being GMT. The returns are on NYSE so I would like to convert to the eastern time zone but I would like to take care of the daylight savings time…
Alex
  • 19,533
  • 37
  • 126
  • 195
7
votes
2 answers

R extract time components from semi-standard strings

Setup I have a column of durations stored as a strings in a dataframe. I want to convert them to an appropriate time object, probably POSIXlt. Most of the strings are easy to parse using this method: > data <- data.frame(time.string = c( + "1 d 2…
SuperAce99
  • 712
  • 6
  • 13
6
votes
1 answer

R as.POSIXct(Sys.Date()) returns date a day early

What am I missing ? Sys.Date() [1] "2011-12-15" as.POSIXct(Sys.Date()) [1] "2011-12-14 19:00:00 EST" # Returning the day before !! as.POSIXct(Sys.Date(), origin="1970-01-01 00:00:00") [1] "2011-12-14 19:00:00 EST" # Still returning day before…
user369599
  • 81
  • 2
6
votes
2 answers

Summarize data within multiple groups of a time series

I have a series of observations of birds at different locations and times. The data frame looks like this: birdID site ts 1 A 2013-04-15 09:29 1 A 2013-04-19 01:22 1 A 2013-04-20 23:13 1 …
sbliss
  • 87
  • 2