r - Bounds of all intervals where a series crosses a fixed level -
i have many 2 columns matrices, one:
x<-structure(c(-3.09, -3.028, -2.965, -2.903, -2.841, -2.778, -2.716, -2.653, -2.591, -2.528, -2.466, -2.404, -2.341, -2.279, -2.216, -2.154, -2.091, -2.029, -1.967, -1.904, -1.842, -1.779, -1.717, -1.654, -1.592, -1.53, -1.467, -1.405, -1.342, -1.28, -1.217, -1.155, -1.093, -1.03, -0.968, -0.905, -0.843, -0.78, -0.718, -0.656, -0.593, -0.531, -0.468, -0.406, -0.343, -0.281, -0.219, -0.156, -0.094, -0.031, 0.031, 0.094, 0.156, 0.219, 0.281, 0.343, 0.406, 0.468, 0.531, 0.593, 0.656, 0.718, 0.78, 0.843, 0.905, 0.968, 1.03, 1.093, 1.155, 1.217, 1.28, 1.342, 1.405, 1.467, 1.53, 1.592, 1.654, 1.717, 1.779, 1.842, 1.904, 1.967, 2.029, 2.091, 2.154, 2.216, 2.279, 2.341, 2.404, 2.466, 2.528, 2.591, 2.653, 2.716, 2.778, 2.841, 2.903, 2.965, 3.028, 3.09, 10.188, 10.195, 10.202, 10.209, 10.216, 10.224, 10.233, 10.241, 10.25, 10.26, 10.27, 10.281, 10.293, 10.305, 10.318, 10.332, 10.346, 10.362, 10.378, 10.396, 10.415, 10.435, 10.456, 10.479, 10.504, 10.53, 10.558, 10.589, 10.622, 10.658, 10.696, 10.738, 10.784, 10.833, 10.887, 10.946, 11.011, 11.082, 11.161, 0.165, 0.095, 0.086, 0.091, 0.348, 12.949, 12.793, 12.673, 12.587, 12.531, 12.503, 12.503, 12.531, 12.587, 12.673, 12.793, 12.949, 0.348, 0.091, 0.086, 0.095, 0.165, 11.161, 11.082, 11.011, 10.946, 10.887, 10.833, 10.784, 10.738, 10.696, 10.658, 10.622, 10.589, 10.558, 10.53, 10.504, 10.479, 10.456, 10.435, 10.415, 10.396, 10.378, 10.362, 10.346, 10.332, 10.318, 10.305, 10.293, 10.281, 10.27, 10.26, 10.25, 10.241, 10.233, 10.224, 10.216, 10.209, 10.202, 10.195, 10.188), .dim = c(100l, 2l), .dimnames = list(null, c("x0", "x2")))
many times, entries of second column (x2) cross below 1 , above.
i trying construct matrix there 1 row each time x2 crosses 1 and, each row, column first value of x0 (the first column) x2<1 , second column first value of x0 x2>1. example, first row of table should have values:
-0.656,-0.343
the second row:
0.406,0.718
and, x, there should not third row.
crossings
d<-diff(x[,2]>1)
indices of crossings
ind<-cbind(which(d==-1)+1,which(d==1)+1)
values @ crossings
matrix(x[ind,1],nrow(ind),ncol(ind))
[,1] [,2] [1,] -0.656 -0.343 [2,] 0.406 0.718
Comments
Post a Comment