I have 2 datasets.
A = 3085 rows, 1 column. B = 527 rows, 1000 columns.
All values in both of these datasets are the names of shapefiles.
I would like to create a new list of A - B[,1]. A.k.a I would like to remove any values from A that appear in the first column of B.
I will eventually be looping this for all 1000 columns.
If anyone can help, it would be much appreciated.
Regards,
If A and B are data.frames or matrices you can use such procedure
A[!(A[,1] %in% B[,1]), 1]
I just now realized fully your question. To loop on all columns of B you can use apply family function. This call will iterate each column of B as x parameter and will return list of length equal to the number of columns of B, each element of the list will be a vector of mismatched elements of A to corresponding column of B.
apply(B, 2, function(x) A[!(A[,1] %in% x), 1])
Something simple (but untested):
x <- A[, 1]
keep <- seq_along(x)
for(i in seq_along(B))
keep <- setdiff(keep, which(x[keep] %in% B[, i]))
A[keep, ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With