posixct

Weird as.POSIXct behavior depending on daylight savings time

佐手、 提交于 2019-12-11 05:07:15
问题 It seems there is a bug in as.POSIXct. Or what is going on? as.POSIXct("27/03/2006 02:05:38", format="%d/%m/%Y %H:%M:%S") [1] "2006-03-27 02:05:38 CEST" as.POSIXct("26/03/2006 02:05:38", format="%d/%m/%Y %H:%M:%S") [1] NA March 26, 2006 happened as far as I know... 回答1: if you really want it printed with the times you can always do. as.POSIXct("26/03/2006 02:05:38", format="%d/%m/%Y %H:%M:%S", tz = "UTC") #[1] "2006-03-26 02:05:38 UTC" Just make sure you do this for all conversions for

How to get origin from POSIXct object

99封情书 提交于 2019-12-10 23:31:56
问题 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 model ( lm() ) which spits my value back out as a numeric. Finally, I want to convert it back to a POSIXct object for my user. The problem is, as.POSIXct() requires an origin which is typically Jan 1, 1970 UTC. But what if my user is working off a different

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

帅比萌擦擦* 提交于 2019-12-10 16:12:56
问题 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 column DF$Day with the day, that I input into the function. Then, I create a subset using that day, which I plot using ggplot2. I figured how to use scale_x_datetime to format the POSIX x axis. Basically, I have it show the hours & minutes only, omitting

Round time by X hours in R?

喜你入骨 提交于 2019-12-10 15:53:46
问题 While doing predicting modeling on timestamped data, I want to write a function in R (possibly using data.table) that rounds the date by X number of hours. E.g. rounding by 2 hours should give this: "2014-12-28 22:59:00 EDT" becomes "2014-12-28 22:00:00 EDT" "2014-12-28 23:01:00 EDT" becomes "2014-12-29 00:00:00 EDT" It's very easy to do when you round by 1 hour - using round.POSIXt(.date, "hour") function. Writing a generic function, like I'm doing below using multiple if statements, becomes

Warning on on POSIXlt(as.POSIXlt(x), …)

人盡茶涼 提交于 2019-12-10 15:45:42
问题 when R was throwing warning messages on this command `setwd("~/Desktop/Project R") Warning message: In format.POSIXlt(as.POSIXlt(x), ...) : unknown timezone 'default/Asia/Kolkata'` So, I tried creating a date for this TZ by entering as.POSIXct("2017-11-01 10:52", "%Y-%m-%d %H:%M", tz = "Asia/Kolkata") [1] "2017-11-01 10:52:00 IST" Warning messages: 1: In strptime(x, format, tz = tz) : unknown timezone 'default/Asia/Kolkata' 2: In as.POSIXct.POSIXlt(as.POSIXlt(x, tz, ...), tz, ...) : unknown

R conversion of week number (UK) to POSIXct issue

ぐ巨炮叔叔 提交于 2019-12-10 11:47:26
问题 I have strings containing UK week numbers (%W in strptime docs) and I can convert a string containing same into POSIXct # create dummy data in June x1 <- as.POSIXct('2012-06-01 01:00', format='%Y-%m-%d %H:%M', tz='UT') (x2 <- format(x1, '%Y %W %a %H %M')) [1] "2012 22 Fri 01 00" as.POSIXct(x2, format='%Y %W %a %H %M', tz='UT') [1] "2012-06-01 01:00:00" So this works fine... However if I want the first of January 2012 it doesn't work - I just get an NA x1 <- as.POSIXct('2012-01-01 01:00',

Plotting POSIXct timestamp series with ggplot2

自作多情 提交于 2019-12-09 15:49:01
问题 I would like to plot the results of a load test. Each row contains a timestamp in seconds and the response time for the request. For example: timestamp <- c(1441229131, 1441229132, 1441229133, 1441229134, 1441229135) response.time <- c(22, 48, 48, 59, 52) lt1 <- data.frame(timestamp, response.time) lt1$datetime <- as.POSIXct(lt1$timestamp, origin="1970-01-01", tz="GMT") However, when I try to plot this, the x axis shows wierd numbers instead od a properly formatted date. g1 <- ggplot(lt1, aes

How to convert specific time format to timestamp in R? [duplicate]

我与影子孤独终老i 提交于 2019-12-09 11:52:55
问题 This question already has answers here : Read csv with dates and numbers (3 answers) Closed 6 years ago . I am working on "Localization Data for Person Activity Data Set" dataset from UCI and in this data set there is a column of date and time(both in one column) with following format: 27.05.2009 14:03:25:777 27.05.2009 14:03:25:183 27.05.2009 14:03:25:210 27.05.2009 14:03:25:237 ... I am wondering if there is anyway to convert this column to timestamp using R. 回答1: First of all, we need to

How to prevent write.csv from changing POSIXct, dates and times class back to character/factors?

大憨熊 提交于 2019-12-09 01:23:48
问题 I have a .csv file with one field each for datetime, date and time. Originally they are all character fields and I have converted them accordingly. At the end of my code, if I do: str(data) I will get datetime: POSIXct date: Date time: Class 'times' atomic [1:2820392] (....) attr(*, "format")= chr "h:m:s" Now, I am very happy with this and I want to create a .csv file, so this is what I have: write.csv(data, file = "data.csv", row.names = FALSE) I have also tried write.table(data, "data.csv",

R shows NA although a value is present

冷暖自知 提交于 2019-12-08 17:23:01
问题 I have two columns of PosixLT times with no NA values , yet NA values show up upon check > sum(is.na(check$start)) [1] 19 > sum(is.na(check$end)) [1] 23 The data is present in the cells, so why does this happen? I have heard that this can happen with PosixLT but even when I convert this to posixCT, there is very strange behavior. How does one go about solving this? > as.POSIXct(check$start, format = "%Y-%m-%d %H:%M:%S", tz = "CST6CDT") [1] NA "2014-03-09 01:35:01 CST" NA "2014-03-09 01:53:30