I would like to ask how should I implement my code if the condition is
if the first condition for x below is 1 & 1
I want my equation to minus 1 on i part only
For example : 1/ (9+10)
then if the second condition is 2 & 1
then I maintain the i value(carry forward) and minus 1 on j part only
So it will become : 1/(9+9)
#There is a total 20 data
x[,1]
and x[,2]
are two separate categories
Type <- c(1,2,1,2,1,1,1,1,2,1)
Eject <- c(1,1,1,1,1,1,1,1,1,1)
x=cbind(Eject,Type)
for(i in 1:n) {
for(j in 1:n) {
if (x[,2] == 1 && x[,1] == 1) {
y[i] = 1/((10-i)+(10-j))
} else if (x[,2]==2 && x[,1] == 1) {
y[j] = 1/((10-i)+(10-j))
}
}
}
question from:
https://stackoverflow.com/questions/66046616/multivariable-for-if-function 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…