I have a vector p of countries and a matrix Z of countries. Some countries in p are not included in Z. I would like an argument that adds countries from p to Z if they are not yet included in Z, but only if they have values that are >0.
Here is an example of the data. In the expected output, Australia should be added to Z, with 0 in all matrix columns since it does not have any matrix data to report. The matrix dimensions should then be 5x5.
p <- c(Afghanistan = 2769, Albania = 93893300, Algeria = 0, Argentina=4550430, Australia=50, Ban = 2)
p <- stack(p)
names(p) <- c("Value", "Area")
#vector
Z <- matrix(c(0,138201.333333333,0,0,0,0,1162.33333333333,0,38.3333333333333,0,0,0,0,0,0,0,300238,0,9675,0), nrow = 4, ncol = 4, byrow=TRUE)
dimnames(Z) = list(c("Afghanistan","Albania","Algeria", "Argentina"),c("Afghanistan","Albania","Algeria", "Argentina")) #matrix
#matrix