Debian Codegraph @

man/interval_included-methods.Rd

raw
1 \name{interval_included}
2
3 \alias{interval_included}
4 \alias{interval_included,Intervals,Intervals-method}
5 \alias{interval_included,Intervals_full,Intervals_full-method}
6
7 \title{Assess inclusion of one set of intervals with respect to another}
8
9 \description{
10 Determine which intervals in the one set are completely included in
11 the intervals of a second set.
12 }
13
14 \usage{
15 \S4method{interval_included}{Intervals,Intervals}(from, to, check_valid = TRUE)
16 \S4method{interval_included}{Intervals_full,Intervals_full}(from, to, check_valid = TRUE)
17 }
18
19 \arguments{
20
21 \item{from}{
22 An \code{"Intervals"} or \code{"Intervals_full"} object, or a
23 vector of class \code{"numeric"}.
24 }
25
26 \item{to}{
27 An \code{"Intervals"} or \code{"Intervals_full"} object, or a
28 vector of class \code{"numeric"}.
29 }
30
31 \item{check_valid}{
32 Should \code{\link{validObject}} be called before passing to
33 compiled code? This, among other things, verifies that endpoints are
34 of data type \code{"numeric"} and the \code{closed} vector/matrix is
35 appropriately sized and of the correct data type. (Compiled code
36 does no further checking.)
37 }
38
39 }
40
41 \value{
42 A list, with one element for each row/component of \code{from}. The
43 elements are vectors of indices, indicating which \code{to} rows (or
44 components, for the \code{"numeric"} method) are completely included
45 within each interval in \code{from}. A list element of length 0
46 indicates no included elements. Note that empty \code{to} elements are
47 not included in anything, and empty \code{from} elements do not
48 include anything.
49 }
50
51 \seealso{
52 See \code{\link{interval_overlap}} for partial overlaps -- i.e., at at
53 least a point.
54 }
55
56 \examples{
57 # Note that 'from' and 'to' contain valid but empty intervals.
58
59 to <- Intervals(
60 matrix(
61 c(
62 2, 6,
63 2, 8,
64 2, 9,
65 4, 4,
66 6, 8
67 ),
68 ncol = 2, byrow = TRUE
69 ),
70 closed = c( TRUE, FALSE ),
71 type = "Z"
72 )
73
74 from <- Intervals(
75 matrix(
76 c(
77 2, 8,
78 8, 9,
79 6, 9,
80 11, 12,
81 3, 3
82 ),
83 ncol = 2, byrow = TRUE
84 ),
85 closed = c( TRUE, FALSE ),
86 type = "Z"
87 )
88 rownames(from) <- letters[1:nrow(from)]
89
90 from
91 to
92 interval_included(from, to)
93
94 closed(to) <- TRUE
95 to
96 interval_included(from, to)
97
98 # Intervals_full
99
100 F <- FALSE
101 T <- TRUE
102
103 to <- Intervals_full(
104 rep( c(2,8), c(4,4) ),
105 closed = matrix( c(F,F,T,T,F,T,F,T), ncol = 2 ),
106 type = "R"
107 )
108
109 type( from ) <- "R"
110 from <- as( from, "Intervals_full" )
111
112 from
113 to
114 interval_included(from, to)
115
116 # Testing
117
118 B <- 1000
119
120 x1 <- rexp( B, 1/1000 )
121 s1 <- runif( B, max=5 )
122 x2 <- rexp( B, 1/1000 )
123 s2 <- runif( B, max=3 )
124
125 from <- Intervals_full( cbind( x1, x1 + s1 ) )
126 to <- Intervals_full( cbind( x2, x2 + s2 ) )
127
128 ii <- interval_included( from, to )
129 ii_match <- which( sapply( ii, length ) > 0 )
130
131 from[ ii_match[1:3], ]
132 lapply( ii[ ii_match[1:3] ], function(x) to[x,] )
133
134 included <- to[ unlist( ii ), ]
135 dim( included )
136
137 interval_intersection( included, interval_complement( from ) )
138 }