matrix not populated as expected in R, based on nrow & ncol