I have a dataframe like this:
> print(A)
5 3 7 6 11 4 20 8 16 18
r01 1 1 1 1 1 1 1 1 1 0
r02 0 0 0 0 0 0 0 1 1 0
r03 1 0 1 0 1 1 0 0 0 0
r04 0 1 0 0 0 1 0 1 0 1
r05 1 1 0 1 1 1 0 0 1 1
And another like this:
> print(B)
head_req_ID tail_req_ID
1 r04 r01
2 r01 r02
3 r05 r03
For each column of A I have to check with the data of B.
B is a structure that indicates the requirements: it indicates that, in order to have 1
in r01
, it must be r04
a 1
. That is,
always has to be the element of the first column to be able to have the element of the second column,
and thus for all rows of B. I put a graphic example
EDIT
I tried the following:
checkImp <- function(x,y,z){
print(c("Columna de A",x))
print(c("Primer elemento de B",y))
print(c("Segundo elemeno de B",z))
print(c("Obtengo el primer índice",indice1 <- which(data$req_ID %in% y)))
print(c("Obtengo el segundo índice",indice2 <- which(data$req_ID %in% z)))
if(x[as.numeric(indice1)] == 0 & x[as.numeric(indice2)] != 0){
x[indice2] <- 0
}
}
mapply(checkImp,A,B[,1],B[,2])
Print output
[1] "Columna de A" "1" "0" "1" "1" "1" "0" "0" "1"
[10] "0" "1" "0" "1" "0" "0" "1" "0" "0"
[19] "0" "0" "1"
[1] "Primer elemento de B" "r04"
[1] "Segundo elemento de B" "r01"
The problem is that I can only compare the column of A with the first row of B, I need to compare the column of A with ALL the data of B.