I have two data frames (x and Y). I need to compare each row in X to every row in Y and if two logicals are met take the value from a column in Y and place it in the column of X (for that specific row). Dataframe X looks like:
The goal is to test each row of X against each row of Y and if X$Long == Y$Longitude & X$Lat==YLattidude for a row to assign the value of Y$Site at the row which meets the condition to X$sink for the specific row being tested.
I would like this to be in a single function with input x and y. I have tried some codes but it is not filling in the values.
This is a sample of the things I have been doing.
**Connectivity_Matrix_function<- function(X,Y){
X$Sink <- c("NA")
for (z in 1:nrow(X)) {
for (i in 1:nrow(Y)) {
if(X[z, 4] == Y[i,2] & X[z,5] == Y[i,3]) { X[z, 11] <- Y[i, 1] }
}
}
}**