I have a vector, i.e. a list that includes 107 country names and values, and a matrix with 203 country names and values. I would like to adjust the list to match the matrix by row names, so that matching country names and values get included and other countries are filled with NA.
Here is a reproducible example. As you can see, Afghanistan is not included in the vector but in the matrix since the matrix includes more countries.
#vector
df <- read.table(header=TRUE,
text="Area Value
Albania 2758
Angola 64772
Argentina 266403082
Australia 251000
Austria 784684
")
#matrix
Z <- matrix(1:25, nrow = 5, ncol = 5, byrow=TRUE, dimnames = list(c("Afghanistan","Albania","Algeria","Argentina","Australia"), c("Afghanistan","Albania","Algeria","Argentina","Australia")))
How can I do this?