Учитывая, что вы хотите, чтобы все элементы находились между минимумом первого столбца и минимумом последнего столбца, вы можете индексировать матрицу напрямую:
dat <- matrix(c(58, 47, 40, 42, 38, 22, 53, 43, 36, 62, 51, 44), byrow = TRUE, ncol = 3)
## grab the two values and sort them (assumes there are no missing values)
## using ncol() is a bit neater than dim(x)[2] for a matrix
minmax <- sort(c(min(dat[,1]), min(dat[,ncol(dat)])))
## subset by direct indexing (as if dat were a vector)
res <- dat[dat >= minmax[1] & dat <= minmax[2]]
## sort the result
sort(res)
[1] 22 36 38 40 42
Я назвал свою матрицу «dat», а не «data», так как это функция в R.