I have some problems to express myself. Probably, that is why I havent found anything which helps me yet. The example should make clear what I want.
Suppose I have a m x m matrix structure of coordinates. Lets say it ranges from A1 to E5 . and I want to subset the rows/columns which are k lines away from the outer coordinates.
In my example k is 2. So I want to select all records in the data frame which have the coordinates B2, B3, B4, C2, C4, D2, D3, D4. Manually, I would do the following:
cc <- data.frame(x=(LETTERS[1:5]), y=c(rep(1,5),rep(2,5),rep(3,5), rep(4,5), rep(5,5)) , z=rnorm(25))
slct <- with(cc, which( (x=="B" | x=="C" | x=="D" ) & (y==2 | y==3 | y==4) & !(x=="C" & y==3) ))
cc[slct,] # result data frame
But if the matrix dimensions increase that is not the way which will work great. Any better ideas?
Rather hard to read but it does the trick.
The first line of comparisons extracts the
k:th column from the left and right edges of the matrix, but not the parts that are closer thankto the upper and lower edges. The second line does the same thing but for rows.