Q:

Match and merge 3 matrices into one matrix of 3 columns

I would like to merge 3 matrices (lat, lon and obs) into one unique matrix (or data.frame) where each value matches with the correspondent ones.
Let's suppose I have the following matrices:
latitude_m

   lat lat lat
lat 3   12  4
lat 5   45  9
lat 12  33  1

longitude_m

   lon lon lon
lon 1   34  3
lon 23   5  1
lon 2    2  9

observations_m

   obs obs obs
obs 45  13   6
obs 22   4   9
obs  2   1  10

How can I get the following:
lat lon obs
3    1   45
5   23   22
12   2    2
12  34   13
45   5    4
33   2    1
4    3    6
9    1    9
1    9   10

Thanks

A:

Akruns solution works well, but just in case there is some information associated with the index of each value it might be wise to store it as an array.
set.seed(1)
lon <- matrix(sample(-180:180, 9), 3)
lat <- matrix(sample(-90:90, 9), 3)
obs <- matrix(round(runif(9)*9, 1), 3)

library(abind)
arr <- abind(lon, lat, obs, along=3)

If you then want to collapse it down to two dimensions it is as easy as resetting dim()
dim(arr) <- c(9, 3)
arr
#      [,1] [,2] [,3]
# [1,]  -85  -79  3.4
# [2,]  -47  -53  7.0
# [3,]   25  -59  8.4
# [4,]  145   32  1.9
# [5,] -108  -23  5.9
# [6,]  139   45  1.1
# [7,]  155   -3  2.4
# [8,]   53   34  3.5
# [9,]   42   81  0.1

