Does R have some similar command to SAS IN?
Here is an example in SAS code:
IF variable1 IN (4,5,6,7) THEN variable2 = 1;
That is, if variable1 assumes values from 4 to 7, variable2 is assigned a value of 1.
Does R have some similar command to SAS IN?
Here is an example in SAS code:
IF variable1 IN (4,5,6,7) THEN variable2 = 1;
That is, if variable1 assumes values from 4 to 7, variable2 is assigned a value of 1.
You can also use the %in%
variavel1 <- 5
if (variavel1 %in% c(4, 5, 6, 7)) {
variavel2 <- 1
}
Try the is.element function.
var1 <- 1
if (is.element(var1, c(1, 2, 4))) {
var2 <- 1
print(var2)
}