Three Dimensional Matrix In R