4
R has some command similar to SAS IN?
Follow an example in SAS code:
variable1 IN (4,5,6,7) THEN variable2 = 1;
That is, if the variable1 assumes the values from 4 to 7, the variable2 is assigned the value 1.
4
R has some command similar to SAS IN?
Follow an example in SAS code:
variable1 IN (4,5,6,7) THEN variable2 = 1;
That is, if the variable1 assumes the values from 4 to 7, the variable2 is assigned the value 1.
3
You can also use the operator %in%
variavel1 <- 5
if (variavel1 %in% c(4, 5, 6, 7)) {
variavel2 <- 1
}
2
Try the function is.element .
var1 <- 1
if (is.element(var1, c(1, 2, 4))) {
var2 <- 1
print(var2)
}
What if var1 = 5
, what value it takes var2
?
@Gradually, I edited the answer. Now var2 only prints if the condition is true. Anyway if the element is not in the list it will return false. example: is.element(5, c(1, 2, 4)).
Browser other questions tagged r sas
You are not signed in. Login or sign up in order to post.
Both ways worked perfectly, thank you very much!
– Henrique Pizarro
Hello Henry, don’t forget to accept the answer you deem most appropriate (all other useful answers can be presented with a positive vote).
– Anthony Accioly
That goes for yours, too other questions.
– Anthony Accioly
Thanks for the warning!
– Henrique Pizarro
You are welcome Henrique. Whenever you have any questions or suggestions about the site you can use meta. Hugs.
– Anthony Accioly