Dear all,

I have two data frames (df1 and df2) and for each timepoint in df1 I want to know: is it whithin any of the timespans in df2? The result (e.g. "no" or "yes" or 0 and 1) should be shown in a new column of df1

Here is the code to create the two data frames (the size of the two data frames is approx. the same as in my original data frames):

# create data frame df1
ti1 <- seq.POSIXt(from=as.POSIXct("2020/01/01", tz="UTC"), to=as.POSIXct("2020/06/01", tz="UTC"), by="10 min")
df1 <- data.frame(Time=ti1)

# create data frame df2 with random timespans, i.e. start and end dates
start <- sort(sample(seq(as.POSIXct("2020/01/01", tz="UTC"), as.POSIXct("2020/06/01", tz="UTC"), by="1 mins"), 5000))
end   <- start + 120
df2 <- data.frame(start=start, end=end)

Everything I tried (ifelse combined with sapply or for loops) has been very very very slow. Thus, I am looking for a reasonably fast solution.

Thanks a lot for any hint in advance !

Cheers,

Thomas

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to