This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: test (see the examples), and the class attribute (see oldClass ) of the result is taken from test and may be inappropriate for the values selected from yes and no . Sometimes it is better to use a construction such as (tmp <- yes; tmp[!test] <- no[!test]; tmp) , possibly extended to handle missing values in test . References Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language . Wadsworth & Brooks/Cole. See Also if . Examples x <- c(6:-4) sqrt(x) #- gives warning sqrt(ifelse(x >= 0, x, NA)) # no warning ## Note: the following also gives the warning ! ifelse(x >= 0, sqrt(x), NA) ## example of different return modes: yes <- 1:3 no <- pi^(0:3) typeof(ifelse(NA, yes, no)) # logical typeof(ifelse(TRUE, yes, no)) # integer typeof(ifelse(FALSE, yes, no)) # double [Package base version 2.11.1 Index ]...
View Full Document
- Fall '10
- Logic, Mathematical logic, Axiom