in.lim {StratigrapheR} | R Documentation |
Finds the intervals encompassing values
Description
This function returns the intervals encompassing x values. This works only if the intervals (as lim objects) are non overlapping and non-adjacent (if certain boundaries are neighbouring, the boundary rule should exclude all, or all but one)
Usage
in.lim(x, lim = NULL, l = NULL, r = NULL, id = 1L, b = "][", index = FALSE)
Arguments
x |
a vector values |
lim |
an object convertible into a lim object: either a vector of length 2 or a list of n left (1st element) and n right (2ndt element) interval limits. The intervals should be non-overlapping and non-adjacent. |
l |
a vector of n left interval limits |
r |
a vector of n right interval limits |
id |
a vector of n interval IDs (default is 1 for each interval) |
b |
a character vector for the interval boundaries rules: "[]" (or "closed") to include both boundaries points, "][" (or "()" and "open") to exclude both boundary points, "[[" (or "[)","right-open" and"left-closed") to include only the left boundary point, and "]]" (or "(]", "left-open", "right-closed") to include only the right boundary point. |
index |
whether the output should be a list of the initial vector and of the corresponding intervals in which they lay (index = FALSE, is the default), or simply the index of the intervals in the initial lim object (index = TRUE) |
Value
a list of the intervals where the x values lay or a vector of their index
See Also
Examples
x <- c(99,1,3,5,2,4,5,6,9,4,8,20,26,52,42,24,25,12,40,10,16,17)
lim <- as.lim(l = c(100,10,20,27), r = c(99,12,27,42), b = "]]")
in.lim(x, lim = lim)
in.lim(x, lim = lim, index = TRUE)
# Applications to Stratigraphy
proxy <- proxy.example # This is a data.frame with (fake) magnetic
# susceptibility (ms) and depth (dt)
# Each sample was taken in a specific bed (not at the boundary between two,
# to make things easier). We will invoke the data of the beds (bed.example)
# and identify the lithology of each sample
res <- in.lim(proxy.example$dt, # Position of each sample
l = bed.example$l, # Left boundary of the beds
r = bed.example$r, # Right boundary of the beds
id = bed.example$litho) # Lithology of each bed (if you wanted
# to know the name of the bed each
# sample is in you would have put
# bed.example$id)
proxy$litho <- res$id # The result provides the id (here the lithology) of
# each interval encompassing the measurement (x, here
# proxy.example$dt)
plot(proxy$ms, proxy$dt, type = "l", xlim = c(-2*10^-8, 8*10^-8))
shale <- subset(proxy, proxy$litho == "S")
points(shale$ms, shale$dt, pch = 4)
limestone <- subset(proxy, proxy$litho == "L")
points(limestone$ms, limestone$dt, pch = 19)
chert <- subset(proxy, proxy$litho == "C")
points(chert$ms, chert$dt, pch = 21, bg = "white")
legend(6.2*10^-8, 25, legend = c("Shale", "Limestone", "Chert"),
pch = c(4,19,21), bg = c(NA, NA, "white"))