Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
213 views
in Technique[技术] by (71.8m points)

r - Multivariable for if function

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...