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

fill sequence of datetimes

I have a data.frame consisting of IDs, DateTimes and Values. For each ID I want to expand the DateTimes so that there is one every hour between the min and max. The ID and Value columns should be filled with their respective values (i.e. not NA).…
sebdalgarno
  • 2,929
  • 12
  • 28
5
votes
3 answers

Converting datetime from character to POSIXct object

I have an instrument that exports data in an unruly time format. I need to combine the date and time vectors into a new datetime vector in the following POSIXct format: %Y-%m-%d %H:%M:%S. Out of curiosity, I attempted to do this in three different…
philiporlando
  • 941
  • 4
  • 19
  • 31
5
votes
1 answer

Using R data.table to subset high frequency time series (a replacement of xts functionality with data.table)

I would like all the data between certain times each day using data.table. Is this the most efficient (speed wise and memory) way to do these kinds of subsetting? R.data.table <- data.table(Time = Sys.time() + 1:86400,…
user6843665
5
votes
2 answers

replace only date in PosixCt class

I have a large dataframe of dates in PosixCt format. My objective is simple: to change all of the dates to one day - 2016-05-01 - while keeping all of the times the same. How would I proceed to replace the first 10 characters in a string (of…
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
5
votes
3 answers

Converting to Local Time in R - Vector of Timezones

I have a set of data from across the US that I am trying to convert into local time for each "subject". I have UTC timestamps on each event and have converted those into POSIXct format, but every time I try to include a vector of tz = DS$Factor or…
Shorthand
  • 176
  • 6
5
votes
1 answer

In R, is the %OSn time format only valid for formatting, but not parsing?

Consider this R code, which uses a defined time format string (the timeFormat variable below) to format and parse dates: time = as.POSIXct(1433867059, origin = "1970-01-01") print(time) print( as.numeric(time) ) timeFormat = "%Y-%m-%d…
HaroldFinch
  • 762
  • 1
  • 6
  • 17
5
votes
1 answer

Adding timezone to POSIXct object in data.table

I have a data.table object with the columns date and time stored as IDate/ITime objects. I also have a time zone column where the time zone is given as character. Now I want to create a column DateTime that is using the POSIXct format. However I…
Wolfgang Wu
  • 834
  • 6
  • 16
5
votes
3 answers

Why read.zoo gives index as dates when times are available

I'm trying to understand my difficulties in the past with inputting zoo objects. The following two uses of read.zoo give different results despite the default argument for tz supposedly being "" and that is the only difference between the two…
IRTFM
  • 258,963
  • 21
  • 364
  • 487
5
votes
3 answers

Using the result of summarise (dplyr) to mutate the original dataframe

I have a rather big dataframe with a column of POSIXct datetimes (~10yr of hourly data). I would flag all the rows in which the day falls in a Daylight saving period. For example if the Daylight shift starts on '2000-04-02 03:00:00' (DOY=93) i would…
Fabio
  • 518
  • 1
  • 4
  • 10
5
votes
1 answer

Converting numeric time to datetime POSIXct format in R

I have a data frame containing what should be a datetime column that has been read into R. The time values are appearing as numeric time as seen in the below data example. I would like to convert these into datetime POSIXct or POSIXlt format, so…
jjulip
  • 1,093
  • 4
  • 16
  • 24
5
votes
1 answer

as.POSIXct rejects +1300 timezone

I'm using as.POSIXct to parse times with timezones, like this: as.POSIXct("2009-01-05 14:19 +1200", format="%Y-%m-%d %H:%M %z") However, if the string includes the timezone information +1300, the function returns NA: > as.POSIXct("2009-01-05 14:19…
rodrigorgs
  • 855
  • 2
  • 9
  • 20
5
votes
1 answer

cumulative sum over time

I have this data: thedat <- structure(list(id = c(" w12", " w12", " w12", " w11", " w3", " w3", " w12", " w45", " w24", " w24", " w24", " w08", " …
user1322296
  • 566
  • 2
  • 7
  • 26
5
votes
2 answers

Date-time conversion in R

I have created a file something like this: > filesInside Date Time 1 01:09:2013 10:35:49.997 2 01:09:2013 10:35:50.197 How could I possibly make a function using as.POSIXct() and I should be get something like this: >…
jeff1234
  • 61
  • 4
5
votes
3 answers

How do I plot time (HH:MM:SS) in X axis in R

I have tried to read through stackoverflow, blogs, books etc but have been unable to find the answer on plotting time in the x-axis in the following format(HH:MM:SS.000) in R and another quantity on the y-axis. I have the following dataset: Time …
Paul Lugano
  • 75
  • 1
  • 2
  • 5
5
votes
2 answers

Aggregate15 minute data to hourly

I have a data frame that looks like this: Timedate TotalSolar_MW 20 2013-06-01 04:45:00 13.0 21 2013-06-01 05:00:00 41.7 22 2013-06-01 05:15:00 81.8 23 2013-06-01 05:30:00 153.0 24 2013-06-01 05:45:00 …
max.mustermann
  • 127
  • 1
  • 1
  • 9