posixct

scale_datetime shifts x axis [duplicate]

拜拜、爱过 提交于 2019-12-06 09:52:13
This question already has answers here : Time series plot gets offset by 2 hours if scale_x_datetime is used (2 answers) Closed 3 years ago . I am trying to plot a time series that has an x axis of class "POSIXct" using ggplot2, which is working up to a point. When I try to manipulate the x axis breaks and labels using scale_x_datetime it generates a one month shift in the x axis. Can anyone explain this, and provide a solution? Example simplified code: start <- as.POSIXct("2014/07/01 00:00:00") end <- as.POSIXct("2014/10/01 23:30:00") interval <- as.difftime("00:30:00") df <- data.frame(t=seq

ifelse on data frame column to replace with date time column values if matched

為{幸葍}努か 提交于 2019-12-06 07:53:58
I need help. I am trying to copy the date_time column values into new column based on matching values of txt_col column and those that are not matched mark as NA . Here is my code: df$new_col <- ifelse(df$txt_col == "apple", df$date_time, NA) However, I get numbers in the new column, instead of date-time : new_col 1477962000 1451755980 1451755980 1451755980 When looking at the str(df) , the column date_time is POSIXct . I tried to convert as.numeric and POSIXct , it didn't work. If you have more elegant ways to do what I am trying to achieve, it would be much appreciated if you share. Thank

Error reading timestamps using “xlsx” package

你说的曾经没有我的故事 提交于 2019-12-06 07:24:54
Data in Excel file looks like TIMESTAMP TYPE BID BIDSIZ 2015-01-04 09:00:00 BID 365 10 2015-04-01 09:00:05 BID 367.8 55 2015-04-01 09:00:33 BID 365 10 2015-04-01 09:00:36 BID 367.8 55 When I run the following code: require(xlsx) f1<-read.xlsx2("Canara_Data.xlsx", sheetName = "BID") f1$TIMESTAMP<-as.POSIXct(f1$TIMESTAMP, format="%Y-%M-%D %H:%M:S") viewing it causes TIMESTAMP to look like View(`f1`) TIMESTAMP X. BID BIDSIZ 42008.375 BID 365 10 42095.37505787037 BID 367.8 55 42095.37538194445 BID 365 10 42095.37541666667 BID 367.8 55 str(f1) # 'data.frame': 18214 obs. of 4 variables: # $

Calculate time difference (difftime) between columns of different rows

梦想的初衷 提交于 2019-12-06 06:47:42
I have data on 'Start' and 'End' time for different jobs, grouped by 'owner': Data <- data.frame( job = c(1, 2, 3, 4, 5), owner = c("name1", "name2", "name1", "name1", "name2"), Start = as.POSIXct(c("2015-01-01 15:00:00", "2015-01-01 15:01:00", "2015-01-01 15:13:00", "2015-01-01 15:20:00", "2015-01-01 15:39:02"), format="%Y-%m-%d %H:%M:%S"), End = as.POSIXct(c("2015-01-01 15:11:11", "2015-01-01 15:17:21", "2015-01-01 15:17:00", "2015-01-01 15:31:21", "2015-01-01 15:40:11"), format="%Y-%m-%d %H:%M:%S") ) For each owner, I want to calculate the idle time between the jobs for each owner, i.e. the

R as.POSIXct() dropping hours minutes and seconds

给你一囗甜甜゛ 提交于 2019-12-06 05:56:19
问题 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

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

大城市里の小女人 提交于 2019-12-06 00:43:45
问题 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 = "Australia/Brisbane") as.POSIXct("2012-08-06 15:32:00", tz = "") all produce the same output on my two (Mac and Windows) boxes: "2012-08-06 15:32:00 EST" The problem here is EST could be any number of timezones: Eastern Standard Time in the USA, or Australian

endpoints in xts using R

房东的猫 提交于 2019-12-05 22:12:52
I am trying to figure out how endpoints selects the times when my data is only weakly regular: that is, some observations are missing. I have 1 minute returns with some minutes missing and I am trying to convert to 5 minute intervals. How will endpoints decide which times to keep? The call I use is: endpoints(ret_1_min_xts, k=5, "minutes") My series looks like this, for example: 1986-02-04 09:32:00 1 1986-02-04 09:33:00 2 1986-02-04 09:34:00 3 1986-02-04 09:35:00 4 1986-02-04 09:36:00 5 1986-02-04 09:37:00 6 1986-02-04 09:38:00 7 1986-02-04 09:39:00 8 1986-02-04 09:40:00 9 1986-02-04 09:41:00

Storing time without date but not as class character

自古美人都是妖i 提交于 2019-12-05 18:59:21
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 PM" "4:23 AM" "6:28 AM" "2:45 PM" "3:08 PM" "3:23 PM" "3:58 PM" I wanted to convert them from class character to time variables. So I used: > as.POSIXct(a$local.time, tz = "", format = "%I:%M %p", usetz = FALSE) This resulted in : [1] "2014-10-31 01:30:00 EDT" "2014-10-31 06:29:00 EDT" "2014-10-31 06:59:00 EDT" "2014-10-31 09:54:00 EDT" [5] "2014-10-31 10:14

How to make an empty vector of POSIXct

别来无恙 提交于 2019-12-05 09:52:47
问题 I want to make an empty vector of POSIXct so that I can put a POSIXct in it: vec <- vector("POSIXct", 10) vec vec[1] <- "2014-10-27 18:11:36 PDT" vec That does not work. Any ideas? 回答1: Since there is no POSIX mode , you cannot initialize a POSIXct vector with vector() alone (see ?mode for a list of all mode types). But we can use .POSIXct to create the vector from a character vector. (x <- .POSIXct(character(10))) ## the same as .POSIXct(vector("character", 10)) # [1] NA NA NA NA NA NA NA NA

POSIXct to numeric using different timezones

自闭症网瘾萝莉.ら 提交于 2019-12-05 07:54:48
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. Yet, when I convert them to a numeric value, the result is different... Could anyone point me to what I am doing wrong? > pst = as.POSIXct('2011-01-10 06:45:00', tz = 'PST') > est = as.POSIXct('2011-01-10 09:45:00', tz = 'EST') > as.numeric(pst) [1] 1294641900 > as.numeric(est) [1] 1294670700 here is my session info: > sessionInfo() R version 2.13.0