posixct

Coercing a POSIXct object to Date object

不打扰是莪最后的温柔 提交于 2019-12-12 11:18:43
问题 Reproducible code: # Loading quantmod library(quantmod) # Please, put in R this structure a <- structure(c(2.4, 2.35, 2.44, 2.44, 2.31, 2.32, 2.41, 2.43, 2.46, 2.42, 2.45, 2.39, 2.3, 2.41, 2.33, 2.37, 2.38, 2.4, 2.275, 2.235, -0.0300000000000002, -0.0499999999999998, 0.0899999999999999, 0, -0.13, 0.00999999999999979, 0.0900000000000003, 0.02, 0.0299999999999998, -0.04, 0.0300000000000002, -0.0600000000000001, -0.0900000000000003, 0.11, -0.0800000000000001, 0.04, 0.00999999999999979, 0.02, -0

as.POSIXct rejects +1300 timezone

喜夏-厌秋 提交于 2019-12-12 10:59:13
问题 I'm using as.POSIXct to parse times with timezones, like this: as.POSIXct("2009-01-05 14:19 +1200", format="%Y-%m-%d %H:%M %z") However, if the string includes the timezone information +1300 , the function returns NA : > as.POSIXct("2009-01-05 14:19 +1300", format="%Y-%m-%d %H:%M %z") [1] NA Aparently +1300 is a valid timezone (NZDT – New Zealand Daylight Time). How to convince R to parse it? 回答1: This was a bug in 3.0.2 release, which was fixed in R-3.1.0 Patched build. 来源: https:/

convert numeric variable into POSIXct

懵懂的女人 提交于 2019-12-12 10:24:36
问题 i have a variable that contains values about " the beginning of time interval expressed as the number of millisecond elapsed from the Unix Epoch on January 1st, 1970 at UTC." (according to data source metadata) This is the head: x$timeInt [1] 1.388068e+12 1.388075e+12 1.388096e+12 1.388051e+12 1.388051e+12 1.388072e+12 So i try to convert it as POSIXct as.POSIXct(x$timeInt, origin = '01-01-1970',tz='UTC') but i get this result [1] "43987-03-01 05:20:00 UTC" "43987-05-23 13:20:00 UTC" "43988

How to manipulate the time part of a date column?

本秂侑毒 提交于 2019-12-12 06:49:06
问题 How do I write this code ( hour is from lubridate package)? Objective: if hour part of PICK_DATE is later than 16:00, the ADJ_PICK_DATE should be next day 03:00. If the hour part of PICK_DATE is earlier than 03:00, then ADJ_PICK_DATE is to be same day 03:00. Problem is, when there is no change needed, the code still adds 3 hours to the PICK_DATE i.e. when the hour part of PICK_DATE is within 03:00 and 16:00. x$PICK_TIME <- cut(hour(x$PICK_DATE), c(-1, 2, 15, 24), c("EARLY", "OKAY", "LATE")) x

as.POSIXct produces 'unknown timezone' error after Mavericks and R upgrade in Mac OSX

故事扮演 提交于 2019-12-12 02:26:37
问题 I'm trying to convert a string to POSIXct in R v3.1.1 on Mac OS X Mavericks (10.9.4). This worked before upgrading Mavericks then R. My very simple code is now giving a warning and I don't understand why :- as.POSIXct("2014-05-24 12:45", "%Y-%m-%d %hh:%mm") [1] "2014-05-24 12:45:00 GMT" Warning messages: 1: In strptime(xx, f <- "%Y-%m-%d %H:%M:%OS", tz = tz) : unknown timezone '%Y-%m-%d %hh:%mm' 2: In as.POSIXct.POSIXlt(x) : unknown timezone '%Y-%m-%d %hh:%mm' 3: In strptime(xx, f <- "%Y/%m/

R: Cut function with POSIXct dates: Creating specific categories based on time of day

独自空忆成欢 提交于 2019-12-12 02:16:15
问题 I have a small training set of data that I am beginning to analyze. The dataset is comprised of hospital procedural codes, values for said procedure, and a date/time stamp. I am attempting to break down the time stamps into 'time of day' categories, as some of the procedural values will vary depending on morning/evening. I have tried using cut() , but I can't seem to figure out how to input specific time intervals for the categories (ex. 00:00 to 06:00 = "Fasting", 06:01- 10:00 = "Morning

Conditionally calculate time differences between rows in R

人走茶凉 提交于 2019-12-11 13:09:20
问题 I'm trying to calculate the time difference between a row and a row that has a column that meets some criteria. Reading in some data: my_data <- data.frame(criteria = c("some text", "some more text", " ", " ", "more text", " "), timestamp = as.POSIXct(c("2015-07-30 15:53:15", "2015-07-30 15:53:47", "2015-07-30 15:54:48", "2015-07-30 15:55:48", "2015-07-30 15:56:48", "2015-07-30 15:57:49"))) criteria timestamp 1 some text 2015-07-30 15:53:15 2 some more text 2015-07-30 15:53:47 3 2015-07-30 15

missing hour in seq function generating time in R?

拜拜、爱过 提交于 2019-12-11 12:48:35
问题 I have a problem in generating proper time sequence using R: fivemin <- seq(as.POSIXct("2014/01/01 0:00:00"), as.POSIXct("2014/04/01 0:00:00"), by="5 mins",tz="EST") time <- data.frame(MasterTime=fivemin) Using above code, I can get a data frame with 25909 observations. However, under Eastern Standard Time (without daylight saving), the number of observations should be 25920. The difference is 1 hour from the transition of daylight saving time on 03/09/20014, because then the time would

How to create day part in R from a vector of POSIXct timestamps?

痴心易碎 提交于 2019-12-11 12:41:55
问题 I have a long series of POSIXct timestamps. I would like to return, for each record a day part, including day of the week. For example: [1] Sunday night [2] Sunday night [3] Sunday afternoon [4] Saturday night [5] Sunday afternoon ... and so on. Below is a small sample of the data: my_dates <- as.POSIXct(c("2000-03-12 19:40:00 AEDT", "2000-03-19 17:40:00 AEDT", "2000-03-26 14:10:00 AEST", "2000-04-01 19:40:00 AEST", "2000-04-09 14:10:00 AEST", "2000-04-16 14:40:00 AEST", "2000-04-22 19:40:00

Combine date as integer and time as factor to POSIXct in R

非 Y 不嫁゛ 提交于 2019-12-11 09:48:49
问题 I know this has been asked several times and I looked at the questions and followed the suggestions. However, I couldn't solve this one. The datetime.csv can be found on https://www.dropbox.com/s/6bvhk4kei4pg8zq/datetime.csv My code looks like: jd1 <- read.csv("datetime.csv") head(jd1) Date Time 1 20100101 0:00 2 20100101 1:00 3 20100101 2:00 4 20100101 3:00 5 20100101 4:00 6 20100101 5:00 sapply(jd1,class) > sapply(jd1,class) Date Time "integer" "factor" jd1 <- transform(jd1, timestamp