Some functions in geomorph require data to be in 3D
array format. A 3D array is a volumetric matrix of p × k × n dimensions
(p landmarks, k coordinates, n specimens). In other words, unlike a
matrix, a 3D array contains information, not just on rows and columns
(landmark number, and xyz values, in the context of geometric
morphometrics), but also on specimen numbers. In that case, let’s first
refresh ourselves on what a 3D array actually looks like:
arrayspecs() (Expand for more details)
Note that the input coordinates can be arranged such that that landmarks can be contained within sets of two or three columns (for the separate coordinates of each landmark), or with all landmark coordinates of a single specimen contained within a single row.
Array <- lizards$coords[1:10,,1:5]
Array[,,1:2]
## , , 57
##
## X Y
## 1 0.35010213 -0.0002647511
## 2 0.17260728 0.0816019683
## 3 0.04424979 0.0367109953
## 4 -0.06467880 0.1321863000
## 5 -0.25086567 0.1131383707
## 6 -0.24969395 0.0332161379
## 7 -0.23737568 -0.0239577907
## 8 -0.25001471 -0.1068288060
## 9 -0.07187573 -0.1344779554
## 10 0.04380526 -0.0395576574
##
## , , 58
##
## X Y
## 1 0.34899033 -0.000274232
## 2 0.17012827 0.083975084
## 3 0.04486904 0.038471849
## 4 -0.06422872 0.132129075
## 5 -0.24816474 0.113486488
## 6 -0.24640883 0.031615036
## 7 -0.26003274 -0.022913979
## 8 -0.24649800 -0.106480551
## 9 -0.06508554 -0.132159633
## 10 0.04493492 -0.041541288
But what if we want to make changes to, or otherwise access, one specific aspect of our array?
The labels of the array; [1,,], [,1,], and [,,1] give us the clue. The structure of an array can be represented as [,,,], with each comma representing each dimension.
Similar to a standard matrix, values in the first dimension [X,,] represent the rows of our data, or in this case, individual landmarks. So if we want to see the second landmark for every specimen in our dataset we simply:
Array[2,,]
## 57 58 59 60 61
## X 0.17260728 0.17012827 0.1740371 0.17338334 0.1695772
## Y 0.08160197 0.08397508 0.0883011 0.08779632 0.0806348
And similarly if we only want to see one of the xyz (1,2, or 3) values for all of our specimens:
Array[,1,]
## 57 58 59 60 61
## 1 0.35010213 0.34899033 0.35456391 0.35358045 0.34945025
## 2 0.17260728 0.17012827 0.17403709 0.17338334 0.16957719
## 3 0.04424979 0.04486904 0.02909230 0.02943864 0.03862491
## 4 -0.06467880 -0.06422872 -0.05918996 -0.05942190 -0.04948392
## 5 -0.25086567 -0.24816474 -0.25108352 -0.25028234 -0.24342451
## 6 -0.24969395 -0.24640883 -0.24601284 -0.24701886 -0.24893451
## 7 -0.23737568 -0.26003274 -0.24571550 -0.24666354 -0.25512243
## 8 -0.25001471 -0.24649800 -0.24542072 -0.24734206 -0.25199230
## 9 -0.07187573 -0.06508554 -0.05705240 -0.05619145 -0.05471546
## 10 0.04380526 0.04493492 0.03013003 0.03099896 0.03727153
And finally, a single specimen can be selected like so:
Array[,,1]
## X Y
## 1 0.35010213 -0.0002647511
## 2 0.17260728 0.0816019683
## 3 0.04424979 0.0367109953
## 4 -0.06467880 0.1321863000
## 5 -0.25086567 0.1131383707
## 6 -0.24969395 0.0332161379
## 7 -0.23737568 -0.0239577907
## 8 -0.25001471 -0.1068288060
## 9 -0.07187573 -0.1344779554
## 10 0.04380526 -0.0395576574
The above methods can be combined in whatever configuration is necessary for the researcher. Multiple values for each of these categories can also be selected, using a couple of different methods, depending on whether the values of interest are consecutive:
For example, to access multiple, consecutive specimens in our dataset (say, specimens one through three), we can do this:
Array[,,1:3]
## , , 57
##
## X Y
## 1 0.35010213 -0.0002647511
## 2 0.17260728 0.0816019683
## 3 0.04424979 0.0367109953
## 4 -0.06467880 0.1321863000
## 5 -0.25086567 0.1131383707
## 6 -0.24969395 0.0332161379
## 7 -0.23737568 -0.0239577907
## 8 -0.25001471 -0.1068288060
## 9 -0.07187573 -0.1344779554
## 10 0.04380526 -0.0395576574
##
## , , 58
##
## X Y
## 1 0.34899033 -0.000274232
## 2 0.17012827 0.083975084
## 3 0.04486904 0.038471849
## 4 -0.06422872 0.132129075
## 5 -0.24816474 0.113486488
## 6 -0.24640883 0.031615036
## 7 -0.26003274 -0.022913979
## 8 -0.24649800 -0.106480551
## 9 -0.06508554 -0.132159633
## 10 0.04493492 -0.041541288
##
## , , 59
##
## X Y
## 1 0.35456391 -0.001641645
## 2 0.17403709 0.088301095
## 3 0.02909230 0.043781102
## 4 -0.05918996 0.139102924
## 5 -0.25108352 0.114240489
## 6 -0.24601284 0.038163766
## 7 -0.24571550 -0.033198379
## 8 -0.24542072 -0.115717944
## 9 -0.05705240 -0.138606151
## 10 0.03013003 -0.046015427
Alternatively, if the specimens of interest are non-consecutive (say, specimens 1, 3, and 5) we simply input a vector of specimen numbers like so:
Array[,,c(1,3,5)]
## , , 57
##
## X Y
## 1 0.35010213 -0.0002647511
## 2 0.17260728 0.0816019683
## 3 0.04424979 0.0367109953
## 4 -0.06467880 0.1321863000
## 5 -0.25086567 0.1131383707
## 6 -0.24969395 0.0332161379
## 7 -0.23737568 -0.0239577907
## 8 -0.25001471 -0.1068288060
## 9 -0.07187573 -0.1344779554
## 10 0.04380526 -0.0395576574
##
## , , 59
##
## X Y
## 1 0.35456391 -0.001641645
## 2 0.17403709 0.088301095
## 3 0.02909230 0.043781102
## 4 -0.05918996 0.139102924
## 5 -0.25108352 0.114240489
## 6 -0.24601284 0.038163766
## 7 -0.24571550 -0.033198379
## 8 -0.24542072 -0.115717944
## 9 -0.05705240 -0.138606151
## 10 0.03013003 -0.046015427
##
## , , 61
##
## X Y
## 1 0.34945025 0.0006472362
## 2 0.16957719 0.0806347994
## 3 0.03862491 0.0419970856
## 4 -0.04948392 0.1318666311
## 5 -0.24342451 0.1334958957
## 6 -0.24893451 0.0238288905
## 7 -0.25512243 -0.0248760429
## 8 -0.25199230 -0.1292026325
## 9 -0.05471546 -0.1340296409
## 10 0.03727153 -0.0407436725