FAQ Database Discussion Community


R as.POSIXct() dropping hours minutes and seconds

r,posixct
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 21:07:39+00:00,7432444.0 2014-10-22 21:07:57+00:00,7432445.0 2014-10-22 21:08:15+00:00,7432446.0 2014-10-22 21:08:33+00:00,7432447.0 2014-10-22 21:08:52+00:00,7432448.0 2014-10-22 21:09:10+00:00,7432449.0 2014-10-22 21:09:28+00:00,7432450.0 After reading in the file,...

Reading a string column in xlsx with date and time values

r,datetime,xlsx,posixct,posixlt
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 entire column as a string...

Reading in a time with fractional seconds and AM/PM

r,datetime,posixct
This is probably a really basic question, but how do I read a datetime with fractional seconds and an AM/PM indicator into R? > x <- "2014/10/20 3:00:49.324 PM" > as.POSIXct(x, format="%Y/%m/%d %H:%M:%S") [1] "2014-10-20 03:00:49 MYT" # wrong; should be 15:00:49 > as.POSIXct(x, format="%Y/%m/%d %I:%M:%S") [1] "2014-10-20 03:00:49 MYT"...

R package constructing time objects from date and hour(integer)

r,datetime,posixct,date-conversion
I have data provided in the form of a date telling the day (format "YYYY-MM-DD", e.g. "2015-03-11" and the hours of the day numbered (0-23). What is the most convenient way to produce time objects of the form "2015-03-11" and hour = 0 -> "2015-03-11 00:00" "2015-03-11" and hour =...

differences between subsetting POSIXlt and POSIXct in R

r,timestamp,posixct,subsetting,posixlt
DATA v1 <- c("2015-01-05 15:00:00", "2015-01-05 15:45:00", "2015-01-05 15:00:30") OPERATIONS v2 <- strptime(v1, '%Y-%m-%d %H:%M:%S') str(v2) POSIXlt[1:3], format: "2015-01-05 15:00:00" "2015-01-05 15:45:00" "2015-01-05 15:00:30" v3 <- v2[!v2$min] # create v3 from v2 eliminating min != 00 RESULT (successful subsetting) str(v3) POSIXlt[1:2], format: "2015-01-05 15:00:00" "2015-01-05 15:00:30" Now creating v4 by...

How to most efficiently convert a character string of “01 Jan 2014” to POSIXct i.e. “2014-01-01” yyyy-mm-dd

regex,r,date,posixct
I already have a partial answer to the problem here, which I understand as far as it is explained: How to most efficiently restructure a character string for fasttime in data.table However, the task has been extended, and needs to deal with a variation of the orginal formatting. I have...

How to create date from datetime (using lubridate)?

r,posixct,lubridate
Assume I have created a variable containing date and time: a <- ymd_hms("2014-01-01 12:23:34") How do I create another variable that only has the date? That is, what should I do to transform a's value to be identical to b's value where b is b <- ymd("2014-01-01") ...

Subtract time in r, forcing unit of results to minutes [duplicate]

r,posix,posixct
This question already has an answer here: Getting consist units from diff command in R 4 answers I successfully subtracted two POSIXct cols of df1 (below). However, since the time differences are >= 1 hour in all rows, R gives the results in hours. I know that this make...

Using ROracle dbWriteTable to write POSIXct back to Oracle DB

r,oracle,date,posixct,roracle
In Oracle DB: DESCRIBE ORACLE_DB_TABLE; |---------------------------------------| | Column Name | Data Type | |---------------------------------------| | TRANSACTION_TIME | DATE | | TRANSACTION_ID | VARCHAR2 (20 Byte) | | TRANSACTION_AMT | NUMBER (38,10)] | |---------------------------------------| In R: > r_data_table TRANSACTION_TIME TRANSACTION_ID TRANSACTION_AMT 1: 2015-04-28 11:12:24 ABC 123 > dbWriteTable(conn, "ORACLE_DB_TABLE", r_data_table, overwrite...

missing :00 values from date-time string

r,osx,datetime,posixct
I have a large date-time series (%Y-%m-%d %H:%M:%S) that reads as follows: [1] 2009-10-16 00:04:30 2009-10-16 00:04:40 2009-10-16 00:04:50 2009-10-16 00:05 [5] 2009-10-16 00:05:10 2009-10-16 00:05:20 Basically the time increments by 10 secs in each step. However, at the whole minute the :00 is missing and is causing issues when...

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

r,xts,quantmod,posixct
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 package....

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

r,datetime,ggplot2,posixct
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 19:03 259 02/11/2011 19:04 548 09/12/2011 20:14 I would like to have a line...

convert character string with no correct format to posixct

r,posixct
I have downloaded some climate reanalysis data, which took a lot of time to convert from grib, to cdf and finally now I've managed to make it work in R. The next issue I have is that time is a character vector, similar to the following: tt =c( "20090101","20090101.25","20090101.5","20090101.75","20090102", "20090102.25","20090102.5","20090102.75","20090103","20090103.25",...