r - Working with multiple if else statements -
i cannot figure out need. here simplification need.
i process each function if number appears in vector, here example:
v <- c(111,88,222,99,555,1,9,6) if(111 %in% v){ x <- 111+0.1 } else if(222 %in% v){ y <- 222+0.1 } else if(555 %in% v){ z <- 555+0.1 }
i process each function if given number found in vector v
.
in above example if else
example give out number 111.1
,222.1
,333.1
, i'm doing wrong here?
basicaly, calculate each function if number appears in vector.
you want if
check evaluated once first 1 true
, following can never checked because preceded èlse
. drop else
clauses:
v <- c(111,88,222,99,555,1,9,6) if(111 %in% v){ x <- 111+0.1 } if(222 %in% v){ y <- 222+0.1 } if(555 %in% v){ z <- 555+0.1 }
Comments
Post a Comment