posixct

How to avoid that anytime(<numeric>) “updates by reference”?

送分小仙女□ 提交于 2019-12-08 15:41:59
问题 I want to convert a numeric variable to POSIXct using anytime . My issue is that anytime(<numeric>) converts the input variable as well - I want to keep it. Simple example: library(anytime) t_num <- 1529734500 anytime(t_num) # [1] "2018-06-23 08:15:00 CEST" t_num # [1] "2018-06-23 08:15:00 CEST" This differs from the 'non-update by reference' behaviour of as.POSIXct in base R: t_num <- 1529734500 as.POSIXct(t_num, origin = "1970-01-01") # [1] "2018-06-23 08:15:00 CEST" t_num # 1529734500

Creating a dummy variable for certain hours of the day

丶灬走出姿态 提交于 2019-12-08 13:34:47
问题 i need some help. I'm currently trying to fit a linear model to hourly electricity prices. So, I was thinking of creating a dummy, which takes the value 1, if the hour of the day is between 06:00 and 20:00. Unfortunately, I have struggled so far. time.cet <- as.POSIXct(time.numeric, origin = "1970-01-01", tz=local.time.zone) hours.S <- strftime(time.cet, format = "%H:%M:%S", tz=local.time.zone) head(time.cet) [1] "2007-01-01 00:00:00 CET" "2007-01-01 01:00:00 CET" "2007-01-01 02:00:00 CET" [4

How to filter or subset specific date and time intervals in R? Lubridate?

最后都变了- 提交于 2019-12-08 10:31:54
问题 I have a dataset consisting of two columns. A datetime column and a column with numerical values. Its a simple dataset, so I did not attach it.. What I need to do, is to filter or subset the data corresponding with a class schedule, so that I get a dataset/dataframe with datetime values and numerical values for the time when the class has lectures only. The class schedule is different from each day of the week, e.g. Mondays 8:00-9.50, 10.30-11.30, 14.50-15:50. Tuesdays 10.30-11.30, 14.10-15

comparing time portion of POSIXct in R

╄→гoц情女王★ 提交于 2019-12-08 10:00:50
问题 I have a data.frame that contains a bunch of POSIXct dates: df <- data.frame(dte=as.POSIXct(c("2001-02-03 14:30:00", "2001-02-04 9:30:00", "2001-02-05 10:30:00")), a=1:3) I would like to extract the part of the df that has the time portion greater than 9:15 AM and less than 5:25 PM. I could extract the components of hour and minute separately and write a comparison but i thought there might be a more elegant way of doing it. Can anyone make a suggestion? My current method would be: df <-

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

落爺英雄遲暮 提交于 2019-12-08 02:01:37
问题 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

endpoints in xts using R

删除回忆录丶 提交于 2019-12-07 12:46:13
问题 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

Storing time without date but not as class character

落爺英雄遲暮 提交于 2019-12-07 12:03:01
问题 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

comparing time portion of POSIXct in R

家住魔仙堡 提交于 2019-12-07 03:11:28
I have a data.frame that contains a bunch of POSIXct dates: df <- data.frame(dte=as.POSIXct(c("2001-02-03 14:30:00", "2001-02-04 9:30:00", "2001-02-05 10:30:00")), a=1:3) I would like to extract the part of the df that has the time portion greater than 9:15 AM and less than 5:25 PM. I could extract the components of hour and minute separately and write a comparison but i thought there might be a more elegant way of doing it. Can anyone make a suggestion? My current method would be: df <- subset(df, (as.numeric(format(dte, "%H")) > 9 & as.numeric(format(dte, "%M")) > 15) | (as.numeric(format

05:00:00 - 28:59:59 time format

你说的曾经没有我的故事 提交于 2019-12-06 19:56:52
问题 I have dataset where time.start vary from 5:00:00 to 28:59:59 (i.e. 01.01.2013 28:00:00 is actually 02.01.2013 04:00:00). Dates are in %d.%m.%Y format. Date Time.start 01.01.2013 22:13:07 01.01.2013 22:52:23 01.01.2013 23:34:06 01.01.2013 23:44:25 01.01.2013 27:18:48 01.01.2013 28:41:04 I want to convert it to normal date format. dates$date <- paste(dates$Date,dates$Time.start, sep = " ") dates$date <- as.POSIXct(strptime(dates$date, "%m.%d.%Y %H:%M:%S")) But obviously I have NA for time > 23

Conditional subsetting by POSIXct interval and another field containing interval

浪尽此生 提交于 2019-12-06 11:12:00
Given a dataset Dat where I have species (SP), Area (AR), and Time (TM) (in POSIXct). I want to subset the data for individuals that were present with Species A, within a half hour prior and after it was recorded, and within the same area, including two adjacent areas (+ and - 1). For example, if species A was present at 1:00 on area 4, I wish to subset all species present from 12:30 to 1:30 in the same day in areas 3,4 and 5. As an example: SP TM AR B 1-jan-03 07:22 1 F 1-jan-03 09:22 4 A 1-jan-03 09:22 1 C 1-jan-03 08:17 3 D 1-jan-03 09:20 1 E 1-jan-03 06:55 4 D 1-jan-03 09:03 1 E 1-jan-03