Take the 2D 5x5 matrix of position values

Code:

```
A <- matrix(c(seq(11, 51, 10), seq(12, 52, 10), seq(13, 53, 10),
seq(14, 54, 10), seq(15, 55, 10)), 5, 5)
# [,1] [,2] [,3] [,4] [,5]
# [1,] 11 12 13 14 15
# [2,] 21 22 23 24 25
# [3,] 31 32 33 34 35
# [4,] 41 42 43 44 45
# [5,] 51 52 53 54 55
```

Suppose I want to grab out that chunk

Code:

```
[,2] [,3]
[2,] 22 23
[3,] 32 33
```

Then I need to define a matrix of position values. For a 2D object, I need a 2D matrix, one that lists the pairs for each position (i.e., the first column lists the row position and the second column lists the column position). It is like taking pairs of values

Now, this is not a particularly apt way to code it, but it illustrates the point

Code:

```
pairs <- c(
c(2, 2),
c(3, 2),
c(2, 3),
c(3, 3)
)
X <- matrix(pairs, 4, 2, byrow = TRUE)
# [,1] [,2]
# [1,] 2 2
# [2,] 3 2
# [3,] 2 3
# [4,] 3 3
A[X]
# [1] 22 32 23 33
```

These are clearly the points that were desired, but given our query they need to be reconstructed how we desired.

Code:

```
matrix(A[X], 4/2, 2) # Notice '4' is the number of points, and '2' is both the divisor and the number of columns.
# [,1] [,2]
# [1,] 22 23
# [2,] 32 33
```

I suspect there is a similar protocol for drilling into higher dimensional R

*arrays*, merely specifying ordered triples, etc. It makes me curious if this cannot be extended to lists. They do not have the tabular form

*per se*, but this is, in essence, nothing more than specifying points into a function to extract values from the given space. Here we extracting matrix values. If it applies to lists, we can extract more complex things. That could pose problems, which is why I wonder if it works. Conceptually, it is intriguing to me. Maybe I'll learn more about that tomorrow!

In closing, let's get a bit more complicated. Suppose I want to grab the points around the center (33), but not including the center. Then I'm interested in

This requires 9 points with an empty slot for what is being excluded.

Code:

```
pairs <- c(2, 2, 3, 2, 4, 2,
2, 3, NA, NA, 4, 3,
2, 4, 3, 4, 4, 4
)
X <- matrix(pairs, 9, 2, byrow = TRUE) # Same pattern as before: [I]matrix(pairs, npts, dim, byrow = TRUE)[/I]
matrix(A[X], 9/3, 3) # Pattern: [I]matrix(A[X], npts/dim, dim)[/I]
# [,1] [,2] [,3]
# [1,] 22 23 24
# [2,] 32 NA 34
# [3,] 42 43 44
```

Jake's boolean matrix inspired me to further investigate this A[X] operation, but I focused on position matrices themselves. I did that largely for pedagogical reasons. The fact is, it is probably not optimal or even convenient. However, when querying our table A, we may not have a condition to utilize that'll generate the boolean matrix we desire. The above situation could actually be generated in that approach pretty simply (simple in other regards)

Code:

```
X <- matrix(FALSE, 5, 5) # dimensions of A
X[2:4, 2:4] <- TRUE # Set them all to true
X[3,3] <- NA # Specify our exclusion points in X
matrix(A[X], 3, 3) # Apply the matrix subset
```

This is certainly nicer than having to specify a bunch of points. We still need to know what it is we're querying from the table, and that is the real brunt of this issue: how to specify queries of our A table through X. I use the term

*query* because it makes a lot of sense, both in the SQL-esque context and in the fact it is representable in terms of boolean matrices that 'answer' the query. The point-method requires knowing the exact points. The boolean method lends itself to more generalization (ranges of points). Using boolean matrices has the benefit of thinking in terms of A. We design X, as above, as a boolean negative of A. We then specify our criteria to populate X with relevant TRUE's. We can then specify any exclusionary points. In reality, though, X may simply be an offspring, if you will, of A. Take, for instance, the example I referenced from the outset. I wanted to adjust all the points within a 10x4 matrix that were negative that were not within the first column. Thus, I exclude the first column and query the matrix: df[-1][df[-1] < 0]. This gives me all the relevant points. But as I said, I was merely

*accessing* these points to change them. Here I have investigated how to generate a subset that maintains the

*structure* of the table.