intervals

how to show an event happened between two dates in R

我只是一个虾纸丫 提交于 2019-12-10 17:57:39
问题 My question seems simple and I hope it is. I have a dataframe that has the date of diagnosis of a disease, a binary variable indicating which drug the patient was on (or exposed and unexposed group), a start and stop date for the drug, and an overall stop date. ID Diag_date Treatment End.date Drug.start drug.end 1 NA 0 15/03/2002 01/01/2002 01/02/2002 1 NA 1 15/03/2002 01/02/2002 01/03/2002 1 NA 0 15/03/2002 01/03/2002 NA 2 01/04/2002 1 01/05/2002 01/01/2015 01/02/2002 2 01/04/2002 0 01/05

MySQL: check if a value is contained in a range interval

自作多情 提交于 2019-12-10 17:43:49
问题 I was wondering if it is possible to check if a string value is contained in a column given that the column contains the start and end values. For example: if the table has a column NR with the following rows: 400-500 45-76,23-25 12,14-19,21 I want to find the row which has the value 421 in it. So the answer should be the first row. Is this possible in mysql? 回答1: You should have two tables: one for columns, one for column ranges. With that, a simple query will retrieve what you need. CREATE

Is there a CPAN module for converting seconds to English?

会有一股神秘感。 提交于 2019-12-10 15:04:30
问题 Is there a CPAN module that can convert a number of seconds to a human-readable English description of the interval? secToEng( 125 ); # => 2 min 5 sec secToEng( 129_600 ); # => 1 day 12 h The format isn't important as long as it's human-readable. I know that it would be trivial to implement. 回答1: Since Perl v5.9.5, the modules Time::Seconds and Time::Piece are part of the core Perl distribution. So you can use them without installing additional modules. perl -MTime::Seconds -e 'my $s=125; my

Sum of intervals lengths from an integer vector

怎甘沉沦 提交于 2019-12-10 13:46:14
问题 Let's say I have this integer vector : > int.vec [1] 1 2 3 5 6 7 10 11 12 13 (created from int.vec <- c(1:3,5:7,10:13) ) I'm looking for a function that will return the sum of the lengths of all intervals in this vector. So basically for int.vec this function will return: 3+3+4 = 10 回答1: We can create a grouping variable by taking the difference of adjacent elements, check whether that is not equal to 1, get the cumsum , use tapply to get the length , and sum the output. sum(tapply(int.vec

Interval set in java

♀尐吖头ヾ 提交于 2019-12-10 13:34:14
问题 I have a list of intervals with integer values [eg. [1, 4], [10, 19] etc.]. Is there a way to put these intervals into some java collections' container [eg. Set] such that I can call a 'union' function on the container. The 'union' function should give me a list of intervals such that if any 2 inserted intervals overlap then they should be merged in the output. I tried using the Range class in Guava but ended up comparing all the intervals against each other before merging. An elegant

Python- Count the frequency of messages within a date range within per dynamic interval

不想你离开。 提交于 2019-12-10 12:09:00
问题 Count the number of messages within a date range per interval. I"m using python 2.6.5 only. For example Start date: 12/11/2014 End date: 12/12/2014 Start time: 02:00 End time: 02:05 Interval: Per 1 min So this translates to how many messages are between each interval of a minute from start date 12/11 to end date 12/12. So my out put will look like this: (does not need to have strings min and messages) datetime(2014, 12, 11, 2, 0) min : 0 messages, datetime(2014, 12, 11, 2, 1) min: 1 message,

Calculating the intersection between two angle intervals

[亡魂溺海] 提交于 2019-12-10 09:38:30
问题 I'm trying to calculate the intersection between two angle intervals, as in the picture below. Unfortunately, the branch at -pi is making the code much uglier than I have hoped. Here is my first draft. Note that I have not tested this code for correctness, but rather have just gone through the scenarios in my head. As you can see in the function branchify , angle intervals are constrained such that from (p)a1 -> (p)a2 counter-clockwise, the difference is at most pi. In otherwise, the

Finding “maximum” overlapping interval pair in O(nlog(n))

为君一笑 提交于 2019-12-10 01:47:43
问题 Problem Statement Input set of n intervals; {[s_1,t_1], [s_2,t_2], ... ,[s_n,t_n]}. Output pair of intervals; {[s_i,t_i],[s_j,t_j]}, with the maximum overlap among all the interval pairs. Example input intervals : {[1, 10], [2, 6], [3,15], [5, 9]} -> There are possible 6 interval pairs. Among those pairs, [1,10] & [3,15] has the largest possible overlap of 7. output : {[1,10],[3,15]} A naive algorithm will be a brute force method where all n intervals get compared to each other, while the

How to stop $interval on leaving ui-state?

∥☆過路亽.° 提交于 2019-12-09 14:32:45
问题 Angular, UI-router. Using $interval in a controller of a state like so: $scope.Timer = null; $scope.startTimer = function () { $scope.Timer = $interval($scope.Foo, 30000); }; $scope.stopTimer = function () { if (angular.isDefined($scope.Timer)) { $interval.cancel($scope.Timer); } }; The problem? The timer persists upon leaving the state. My understanding was that the $scope and the controller are essentially "destroyed" when a state is left. So, based on that, the timer should stop (Within

Interval sets algebra in R (union, intersection, differences, inclusion, …)

佐手、 提交于 2019-12-09 06:14:30
问题 I am wondering whether a proper framework for interval manipulation and comparison does exist in R. After some search, I was only able to find the following: - function findInterval in base Package. (but I hardly understand it) - some answers here and there about union and intersection (notably: http://r.789695.n4.nabble.com/Union-Intersect-two-continuous-sets-td4224545.html) Would you know of an initiative to implement a comprehensive set of tools to easily handles frequent tasks in interval