posixct

Conditional subsetting by POSIXct interval and another field containing interval

三世轮回 提交于 2019-12-22 14:44:40
问题 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

POSIXct to numeric using different timezones

一世执手 提交于 2019-12-22 05:33:31
问题 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]

ggplotly() does not display geom_vline / geom_hline when data is POSIXct

纵然是瞬间 提交于 2019-12-21 20:03:52
问题 I am trying to make a graph with "time markers". These time markers are vertical lines for certain dates. Time data are POSIXct format. I would like to use the awesome interactive interface of Plotly and use my ggplot objects in it. The problem is that these "time markers" doesn't show in after using ggplotly(). I ave already tried with plotly::add_segments() but it does not work. Here are two reproductible examples : 1. With non-POSIXct data it works fine # dummy dataset df2 = data.frame(id

Modifying timezone of a POSIXct object without changing the display

北慕城南 提交于 2019-12-20 10:39:32
问题 I have a POSIXct object and would like to change it's tz attribute WITHOUT R to interpret it (interpret it would mean to change how the datetime is displayed on the screen). Some background: I am using the fasttime package from S.Urbanek, which take strings and cast it to POSIXct very quickly. Problem is that the string should represent a datetime in "GMT" and it's not the case of my data. I end up with a POSIXct object with tz=GMT , in reality it is tz=GMT+1 , if I change the timezone with

Converting character to timestamp in dataframe

时光总嘲笑我的痴心妄想 提交于 2019-12-20 03:25:08
问题 I have a timestamp in a dataframe that is recognized as a character class. For some reason, I am not able to convert it to a poxis timestamp. Here is a sample of the data. ID dateTime stage 1 2016-11-01T00:00:00.000Z 4.82 2 2016-11-01T00:15:00.000Z 4.83 3 2016-11-01T00:30:00.000Z 4.84 4 2016-11-01T00:45:00.000Z 4.85 5 2016-11-01T01:00:00.000Z 4.86 6 2016-11-01T01:15:00.000Z 4.87 I have tried using the following. format(df$dateTime, "Y%-%m-%d %h:%m") as.Date(df$dateTime, "Y%-%m-%d %h:%m") as

convert date to year month representation in R

孤者浪人 提交于 2019-12-20 01:05:09
问题 I have a Date , and am interested in representing it as an integer of yyyymm form. Currently, I do: get_year_month <- function(d) { return(as.integer(format(d, "%Y%m")))} mydate = seq.Date(from=as.Date("2012-01-01"), to=as.Date("5012-01-01"), by=1) system.time(ym <- get_year_month(mydate)) # user system elapsed # 5.972 0.974 6.951 This is very slow for large datasets. Is there a faster way? Please provide timings for your answers so they can be easily compared. Use the above example. 回答1:

How to initialize data.frame with column of type POSIXct?

风格不统一 提交于 2019-12-19 05:17:03
问题 I can initialize a data.frame via df <- data.frame(a=numeric(), b=character()) But how do I define a column of type POSIXct? df <- data.frame(a=numeric(), b=character(), c=POSIXct()) won't work. 回答1: You can try df <- data.frame(a=numeric(), b=character(), c=as.POSIXct(character())) Similarly, you can create a POSIXct column of NA s in a data frame with > 0 rows by creating a new column with as.POSIXct(NA) . 回答2: An additional tip to the above initialization: If you begin rbind() activities

rounding times to the nearest hour in R [duplicate]

别等时光非礼了梦想. 提交于 2019-12-18 15:30:51
问题 This question already has an answer here : Round a POSIX date and time (posixct) to a date relative to a timezone (1 answer) Closed 6 years ago . I have data in the format time <- c("16:53", "10:57", "11:58") etc I would like to create a new column where each of these times is rounded to the nearest hour. I cannot seem to get the POSIX command to work for me. as.character(format(data2$time, "%H:%M")) Error in format.default(structure(as.character(x), names = names(x), dim = dim(x), : invalid

r - converting POSIXct to milliseconds

会有一股神秘感。 提交于 2019-12-17 20:31:04
问题 From ?POSIXct we know that Class "POSIXct" represents the (signed) number of seconds since the beginning of 1970 (in the UTC time zone) as a numeric vector. Therefore, I've assumed that to get a POSIXct value in milliseconds we need to multiply by 1000 Consider the days in December 2015 ## generate sequence of days in December 2015 d <- seq(as.POSIXct("2015-12-01"), as.POSIXct("2015-12-31"), by = 60*60*24) # [1] "2015-12-01 AEDT" "2015-12-02 AEDT" # ... # [29] "2015-12-29 AEDT" "2015-12-30

Speedup conversion of 2 million rows of date strings to POSIX.ct

佐手、 提交于 2019-12-17 18:53:22
问题 I have a csv which includes about 2 million rows of date strings in the format: 2012/11/13 21:10:00 Lets call that csv$Date.and.Time I want to convert these dates (and their accompanying data) to xts as fast as possible I have written a script which performs the conversion just fine (see below), but it's terribly slow and I'd like to speed this up as much as possible. Here is my current methodology. Does anyone have any suggestions on how to make this faster? dt <- as.POSIXct(csv$Date.and