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

xts to.weekly returns both Fridays and Mondays as the end of the week

I don't seem to be able to get the to.weekly and endpoints (which is used by to.weekly) functions in xts to give me the correct end days of weeks for most types of date data. I've had this problem with both the CRAN and R-Forge versions of the xts…
4
votes
1 answer

R ggplot group by date and plot time in the x axis from the same datetime

I have a df with an integer variable, counts, and a POSIXct datetime variable. The datetime variable represents minute intervals of different days: counts datetime 246 02/11/2011 19:00 237 02/11/2011 19:01 268 02/11/2011 19:02 496 02/11/2011…
user3507584
  • 3,246
  • 5
  • 42
  • 66
4
votes
1 answer

POSIXct to character via strftime() is yielding wrong result

I am having issues extracting the correct character values from a POSIXct datetime object using strftime(). The dput() of my sample data is below: dput(df1) structure(list(FlowDate3 = structure(c(1388534400, 1388534400, 1388534400, 1388534400,…
stokeinfo
  • 135
  • 1
  • 2
  • 8
4
votes
2 answers

Exclusive time intervals in R's lubridate

Take two intervals: [1,6) and [6,12). Number 6 belongs in the second but not the first. Can the same be accomplished in lubridate? (This deals with the issue in Python...) library(lubridate) date1 <- ymd(20010101); date3 <- ymd(20010103); date6 <-…
emagar
  • 985
  • 2
  • 14
  • 28
4
votes
1 answer

R - subset dataframe by Time only

I have been looking around but I still couldn't find a way to subset my dataframe by time, here is the sample data: Duration End Date Start Date 228 2013-01-03 09:10:00 2013-01-03 09:06:00 1675 2013-01-04 17:34:00…
user3773503
  • 161
  • 2
  • 5
  • 12
4
votes
1 answer

R creating XTS object using time string

I want to create an xts object using the below data frame. I understand since this is a combination of factors and combination of numeric values it cannot be in a single xts object. I am happy to create seperate objects with grouping done just by…
user3840089
  • 41
  • 1
  • 2
4
votes
1 answer

Account for daylight savings when converting from GMT in R

I've been searching around on stackoverflow for about 2 hours now and I can't seem to answer this, very basic question. Not sure if it's how I expect things to work or R that is the issue. I haven't found this specific question here, but if it's…
Nova
  • 5,423
  • 2
  • 42
  • 62
4
votes
1 answer

R - ggplot2 - How to use limits on POSIX axis?

What is the smartest way to manipulate POSIX for use in ggplot axis? I am trying to create a function for plotting many graphs (One per day) spanning a period of weeks, using POSIX time for the x axis. To do so, I create an additional integer…
M. Momtaz Hegazy
  • 173
  • 1
  • 12
4
votes
2 answers

Add a second to duplicated POSIXct dates

I am trying to add single seconds to any repeated dates in my data frame. i.e. from this: value date 18 2013-07-09 16:49:23 62 2013-07-09 18:01:36 64 2013-07-09 18:46:51 29 …
Julia
  • 1,369
  • 4
  • 18
  • 38
4
votes
4 answers

Subset POSIXct time by odd or even seconds

I would like to subset a data frame in order to keep only observations where the seconds are an even number. You can download a small part of my data here (100 rows). The first 6 rows look like this: Timestamp C01 C02 C03 C04 C05 C06 C07…
americo
  • 1,013
  • 8
  • 17
4
votes
2 answers

R- date time variable loses format after ifelse

I have a variable in the proper POSIXct format, converted with ymd_hms(DateTime) {lubridate}. However, after a transformation the variable loses its POSIXct format: daily$DateTime<- ifelse(daily$ID %in% "r1_1"|daily$ID %in% "r1_2", …
fede_luppi
  • 1,063
  • 4
  • 17
  • 29
4
votes
2 answers

Coercing a POSIXct object to Date object

Reproducible code: # Loading quantmod library(quantmod) # Please, put in R this structure a <- structure(c(2.4, 2.35, 2.44, 2.44, 2.31, 2.32, 2.41, 2.43, 2.46, 2.42, 2.45, 2.39, 2.3, 2.41, 2.33, 2.37, 2.38, 2.4, 2.275, 2.235, …
Lisa Ann
  • 3,345
  • 6
  • 31
  • 42
4
votes
2 answers

range of POSIXct dates in lists

Consider this list of POSIXct dates: times <- list(as.POSIXct(c("2012-07-26 00:30", "2012-07-26 6:20", "2012-07-26 10:40", "2012-07-26 15:50")), as.POSIXct(c("2012-07-26 01:15", "2012-07-26 10:10", …
nico
  • 50,859
  • 17
  • 87
  • 112
3
votes
3 answers

R converting POSIXct dates with BST/GMT tags using as.Date()

I need to use as.Date on the index of a zoo object. Some of the dates are in BST and so when converting I lose a day on (only) these entries. I don't care about one hour's difference or even the time part of the date at all, I just want to make sure…
SWilliams
  • 691
  • 7
  • 28
3
votes
1 answer

Dividing rows when time is overlapping in R

I have dataframe that was created from the fusion of two dataframes. Both spanned over the same time intervall but contained different information. When I put them together, the info overlapped since there is no holes in the time interval of one of…
PEL
  • 33
  • 3