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

Remove seconds from time in R

I am trying to remove the seconds from a column of hours in POSIXct format: #"2016-04-02 10:33:45 COT" "2016-04-02 22:19:24 COT" #"2016-04-09 17:47:13 COT" "2016-04-13 16:56:23 COT" x <- structure(c(1459589625, 1459631964, 1460220433, 1460562983), …
anitasp
  • 577
  • 4
  • 13
  • 35
6
votes
0 answers

How to get origin from POSIXct object

I have a function like so: foo = function(time_in){ # code here that changes POSIXct to numeric time_out = as.POSIXct(time_in, origin = '1970-01-01') } where the user enters time_in as a POSIXct object. I use this parameter in a linear…
CephBirk
  • 6,422
  • 5
  • 56
  • 74
6
votes
1 answer

Joining a POSIXct column to Date column using data.table in R

In the following example, can someone explain to me why the date 2015-03-31 changed to 1034-04-03? dt1 = data.table(id = c(1,2), date = as.POSIXct("2015-03-31 BST"), key = "id") dt1 # id date # 1: 1 2015-03-31 # 2: 2 2015-03-31 dt2 =…
chengcj
  • 888
  • 2
  • 8
  • 22
6
votes
3 answers

R as.POSIXct() dropping hours minutes and seconds

I am experimenting with R to analyse some measurement data. I have a .csv file containing more than 2 million lines of measurement. Here is an example: 2014-10-22 21:07:03+00:00,7432442.0 2014-10-22 21:07:21+00:00,7432443.0 2014-10-22…
jdepypere
  • 3,453
  • 6
  • 54
  • 84
6
votes
2 answers

How to extract correct date from POSIXct element?

How can I get the correct date from the first column in my code? test <- data.frame(posixdate = c("2013-05-01 00:59:00", "2013-05-01 01:59:00", "2013-05-01 02:59:00", "2013-05-01 03:59:00")) test$posixdate <- as.POSIXct(test$posixdate,…
Aki
  • 409
  • 2
  • 6
  • 15
6
votes
1 answer

Trouble with date format using the function as.POSIXct in R

I'm working with a date format of YYYY-mm-ddTHH:MM:SS.000Z (2014-02-05T08:45:01.326Z) or that has a separator T that separates the date from the time, and time indicator Z or "Zulu time" (UTC). I'm trying to store the timestamp as a class POSIXct…
Carmen
  • 117
  • 1
  • 7
6
votes
2 answers

POSIXct to numeric using different timezones

I think I must not understand how POSIXct works, or something. As far as I understand, it is seconds since epoch, with epoch being a standard time like 1970-01-01 GMT. I take two POSIXct times one in EST one in PST that are the same absolute time.…
vc273
  • 699
  • 6
  • 10
6
votes
1 answer

understanding dates/times (POSIXc and POSIXct) in R

I'm reading a table and it contains strings that describe timestamps. I just want to convert from string to a built-in datetime type... R> Q <- read.table(textConnection(' tsstring 1 "2009-09-30 10:00:00" 2 "2009-09-30 10:15:00" 3…
mariotomo
  • 9,438
  • 8
  • 47
  • 66
6
votes
4 answers

Adding missing rows

The format of my excel data file is: day value 01-01-2000 00:00:00 4 01-01-2000 00:01:00 3 01-01-2000 00:02:00 1 01-01-2000 00:04:00 1 I open my file with this: ts = read.csv(file=pathfile, header=TRUE,…
user2366057
6
votes
2 answers

Exclude rows with certain time of day

I have a time series of continuous data measured at 10 minute intervals for a period of five months. For simplicity's sake, the data is available in two columns as follows: Timestamp Temp.Diff 2/14/2011 19:00 -0.385 2/14/2011 19:10…
lhmv
  • 85
  • 1
  • 6
6
votes
1 answer

timezones in R: how to avoid ambiguous terms such as EST?

I have a series of character timestamps in R. When I change their class to POSIXct using intuitive methods, R assigns the ambiguous timezone EST. For example: as.POSIXct("2012-08-06 15:32:00") as.POSIXct("2012-08-06 15:32:00", tz =…
sfuj
  • 231
  • 7
  • 11
5
votes
2 answers

How to preserve decimal values when converting POSIXct to character?

> t <- Sys.time() > ct <- as.character(t) > t - as.POSIXct(ct) Time difference of 0.4370408 secs The above example indicates that precision is lost when converting POSIXct to character. How to preserve the exact value when converting to character…
5
votes
4 answers

Reconvert numeric date to POSIXct R

I have a date that I convert to a numeric value and want to convert back to a date afterwards. Converting date to numeric: date1 = as.POSIXct('2017-12-30 15:00:00') date1_num = as.numeric(date1) # 1514646000 Reconverting numeric to…
ben_aaron
  • 1,504
  • 2
  • 19
  • 39
5
votes
1 answer

combining POSIXct gives wrong hours

I have a list of dates that I was trying to use Reduce on and realized that the hours were being changed when I combined the vectors. Here's an example: x = structure(1315714440, tzone = "UTC", class = c("POSIXct", "POSIXt")) y =…
svenhalvorson
  • 1,090
  • 8
  • 21
5
votes
1 answer

Timezone for as.POSIXct not working

I have a dataframe with dates and I am trying to convert it to a POSIXct object but I am unable to specify timezone. Any idea why this is happening? > str(dates) 'data.frame': 3171 obs. of 3 variables: $ Date : Date, format: "2013-05-14"…
phil_t
  • 851
  • 2
  • 7
  • 17