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

time difference between date[i + 1] and date[i] by group

I would like to calculate time difference (in hours) between tab$date[i + 1] and tab$date[i] by group. Here my code: setDT(tab) system.time(tab <- tab[ , diffTime := c(0,diff(date, units="hours")), by="ID"]) tab$diffTime <- round(tab$diffTime) The…
Nell
  • 559
  • 4
  • 20
3
votes
1 answer

Why does R not handle daylight savings consistently among years?

I encountered a strange situation while converting time stamps between "America/Detroit" and "GMT". Upon closer inspection I discovered that R converted times between 1 and 2 am on the day daylight savings ends differently in 2010 and 2011. In 2010…
user5270480
3
votes
1 answer

Reading a string column in xlsx with date and time values

I am reading a .xlsx file using R. One of the columns is called "Date" and it has the following format: "20/10/2014 12:00:00 am". However, when I read the file using R's xlsx package, the value becomes 41932-- class factor. How can I read the…
EFL
  • 938
  • 4
  • 11
  • 23
3
votes
1 answer

How to copy specific values from one data column to another while matching other columns in R?

I've searched a number of places (stackoverflow, r-blogger, etc), but haven't quite found a good option for doing this in R. Hopefully someone has some ideas. I have a set of environmental sampling data. The data includes a variety of fields (visit…
NWdev
  • 483
  • 1
  • 6
  • 19
3
votes
3 answers

R:Converting from Character to POSIXct loses hours and minutes

Good morning, I'm trying to convert from character to POSIXct, but when I do, I lose the hours and minutes from the data. hourlyData (dataframe) Login Expo EquityUSD Period UnrealizedProfitUSD 1 252957 0.00 …
Mike
  • 1,049
  • 5
  • 20
  • 46
3
votes
2 answers

Storing time without date but not as class character

I have a local.time column in my data frame of class character containing elements like this : > a$local.time [1] "1:30 AM" "6:29 AM" "6:59 AM" "9:54 AM" "10:14 AM" "10:34 AM" "12:54 PM" "1:15 PM" "1:20 PM" [10] "1:20 PM" "2:15 PM" "2:15…
vagabond
  • 3,526
  • 5
  • 43
  • 76
3
votes
2 answers

How to convert a factor vector to POSIXct in ff or ffbase

After reading in a large data set with read.csv.ffdf, one of the columns is time. Such as 2014-10-18 00:01:02, for 1 million rows in that column. That column is a factor. How do I convert it to POSIXct supported by ff? Simply using as.POSIXct() just…
MM Cui
  • 51
  • 6
3
votes
3 answers

Wrong units displayed in data.table with POSIXct arithmetic

When durations are computed in data.table (v1.9.2), the wrong units can be printed with POSIXct arithmetic. It seems the first units are chosen. require("data.table") dt <- data.table(id=c(1,1,2,2), event=rep(c("start", "end"),…
alexperrone
  • 667
  • 5
  • 12
3
votes
2 answers

ggplot2: shade alternate days with POSIXct timestamp data

I can plot a line of a variable vs timestamp (plot p1 below). However, I'd like to shade the plot for alternate days. The data has an entry once an hour for two days. dat <-structure(list(TIMESTAMP = structure(c(2L, 3L, 14L, 19L, 20L, 21L, 22L,…
nofunsally
  • 2,051
  • 6
  • 35
  • 53
3
votes
1 answer

Searching for nearest date in data frame

I have two data frames: purchases: time quantity 1: 2013-07-31 03:42:02 30 2: 2013-07-31 03:59:32 30 3: 2013-07-31 04:02:22 28 .... history: time price 1:…
Julia
  • 1,369
  • 4
  • 18
  • 38
3
votes
1 answer

as.Date not preserving hour and min information in R

I read in a csv to a data frame as follows: data <- read.csv("Prices.csv", stringsAsFactors = FALSE) data$Timestamp <- as.POSIXct(data$Timestamp, format="%m/%d/%y %H:%M") I tried to use the below but the hour and min data was removed which is my…
mks212
  • 901
  • 1
  • 18
  • 40
3
votes
3 answers

POSIXct in a regression as continuous variable?

I'm trying to fit a regression with time of day as a continuous predictor, and a binary TRUE/FALSE outcome. My time of day variable looks like this: > class(sched_SMS_time) [1] "POSIXct" "POSIXt" > head(sched_SMS_time) [1] NA "2014-01-01…
user3144759
  • 95
  • 3
  • 7
3
votes
1 answer

Time difference in R: POSIXct error

I am using this code to calculate time difference. ctym <- lapply(G, function(x) x[k,2]) y <- lapply(G, function(x) x[j,2]) t1 <- c(y,ctym) dt1 <- as.POSIXct(t1) dtyme <- difftime(dt1[2],dt1[1],units = "mins") Output for t1 is: [[1]] …
anu
  • 295
  • 2
  • 7
  • 15
3
votes
1 answer

POSIXct subsecond output

I am not sure if this is just an output issue, but just wanted to check. I have the following character string that I would like to convert to POSIXct, but unlike traditional POSIXct I have sub-second accuracy that I would like to maintain, as I…
h.l.m
  • 13,015
  • 22
  • 82
  • 169
3
votes
5 answers

extract part of a date in a dataframe column

thanks for your help in advance. i am working with the getQuote function in the quantmod package, which returns the following data frame: is there a way to modify all the dates in the first column to exclude the time stamp, while retaining the data…
jonnie
  • 745
  • 1
  • 13
  • 22