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

Change time format within loop

I got a long text file with multiple columns of which the first contains the time stamp. The format is like that: 2016-02-19T06:27:48 I tried convertig this to a POSIXct format: test1 <- "2016-02-19T06:27:48" z <-…
GeoEki
  • 437
  • 1
  • 7
  • 20
0
votes
1 answer

Turning date strings into usable date objects in R

My strings look like: [1] "Sunday, April 10, 2016" "Saturday, April 16, 2016" I would like to apply an algorithm in R so they each read something like this and have a Class POSIXlt or POSIXct: [1] "04/10/2016" "04/16/2016" I tried to use…
IRNotSmart
  • 351
  • 6
  • 18
0
votes
1 answer

R as.POSIXct timezone issue

I'm confused by the as.POSIXct in R. I use the following code to convert values in columns to one column with Date and Time. fname$DateTime <- as.POSIXct(paste(fname$yy, fname$mm, fname$dd, fname$HH, fname$MM), format = "%y %m %d %H %M") Then, I…
Kuo-Hsien Chang
  • 925
  • 17
  • 40
0
votes
1 answer

R: convert Date/Time columns to POSIXct

I have a dataset that the timestamp was not stored in one single column. The timestamp was separated in different six columns as YY, MM, DD, hh, mm and ss. Here is it looks like: YY MM DD hh mm ss 15 6 12 16 0 …
Kuo-Hsien Chang
  • 925
  • 17
  • 40
0
votes
2 answers

How to unlist result of lapply involving function(x) as.Date(as.POSIXct(x, origin = "1970-01-01"))

I've got a list that is the result of the following command: lapply(data$displayDate, function(x) as.Date(as.POSIXct(x, origin = "1970-01-01"))) That comes out looking like this: > data$displayDateDay[1:10] [[1]] [1] "2015-05-02" [[2]] [1]…
helloB
  • 3,472
  • 10
  • 40
  • 87
0
votes
1 answer

R data.table convert date column to month

I have the following toy data.table x = data.table(dt = c('2015-01-01','2015-02-01','2016-04-01')) I'm trying to add an extra column to the table which has the three letter abbreviation of the date. I tried x$dt = strptime(x$dt,'%b') but it…
broccoli
  • 4,738
  • 10
  • 42
  • 54
0
votes
0 answers

R axis.POSIXct() at 10 minute intervals?

I want to plot a time series with a mark on the x-axis every 10 minutes. Like: 09:10 09:20 09:30 09:40 09:50 10:00 10:10 10:20 and so on. Signal was sampled at 10 Hz sampling frequency. My data frame column df$t is class "POSIXct" "POSIXt". I…
0
votes
1 answer

how do you convert to datetime in R

I am trying to convert this t field to datetime in R. This is the vector: dput(t) "01-DEC-15 04.50.14.000000000 PM" I tried this: tt<-as.POSIXct(t, format="%d-%b-%Y %I.%M.%S %p") when I print out the tt, I get NA. Any ideas what I'm doing wrong?
user1471980
  • 10,127
  • 48
  • 136
  • 235
0
votes
0 answers

Why don't I get the difference between two dates when using difftime in R?

I'm trying to calculate the difference between two dates using a dateRangeInput. I can use both of the dates as a value but when I try to subtract them using difftime nothing happens. Here's my code: date1 <- input$daterange[2] date2 <-…
0
votes
1 answer

How to add time (not minutes/seconds etc, just time E.g., 17:30:00) for one particular day to a list of POSIXct dates in R?

I have a data that consists of date and time which are in POSIXct format as shown below : > DayandTime date_time 1 2015-10-01 11:13:25 2 2015-10-01 12:38:09 3 2015-10-01 17:12:00 4 2015-10-02 11:44:05 5 2015-10-05 13:45:07 6 …
sunitprasad1
  • 768
  • 2
  • 12
  • 28
0
votes
0 answers

as.Date converts wrong date from POSIXct data

I have 3848 rows of POSIXct data - stop times of bike trips in the month of April. As you can see, all of the data is in POSIXct format and is within the range of the month of April. length(output2_stoptime) [1] 3848 head(output2_stoptime) [1]…
iskandarblue
  • 7,208
  • 15
  • 60
  • 130
0
votes
0 answers

as.POSIXct() can't convert a particular time

I use as.POSIXct() to convert character to time stamp. It works well on my data frame except one entry: as.POSIXct("03/29/2015-02:49:13", format = "%m/%d/%Y-%H:%M:%S") This returns NA. I tried it with strptime() as…
Vincent
  • 87
  • 1
  • 7
0
votes
1 answer

When an R vector function call has an error, which element caused it?

I have a long vector of date strings that I want to convert to POSIXct objects. When I call as.POSIXct I get this error: Error: character string is not in a standard unambiguous format How do I find which element of the vector caused the error? For…
0
votes
2 answers

Convert a column to datetime by removing certain parts of characters

I have a df like below and I am trying to convert the datettime column to a datetime format. ID <- c("A","A","B","B") datettime <- c("2015-12-03T13:04:06-06:00","2015-12-03T13:54:06-06:00","2015-12-03T16:04:06-06:00","2015-12-03T19:54:06-06:00") df…
Sharath
  • 2,225
  • 3
  • 24
  • 37
0
votes
0 answers

In R program, lapply returns incorrect output when list includes POSIXct types

I'm writing a function to iterate over the columns in a data frame to build up a list of each by name and by type. I'm using lapply to get the work done. I have come across a strange problem where if the type of the column is a POSIXct then my…