Tutorial by Examples

There are two sorts of logical operators: those that accept and return vectors of any length (elementwise operators: !, |, &, xor()) and those that only evaluate the first element in each argument (&&, ||). The second sort is primarily used as the cond argument to the if function. Logic...
To coerce a variable to a logical use the as.logical() function. > x <- 2 > z <- x > 4 > z [1] FALSE > class(x) [1] "numeric" > as.logical(2) [1] TRUE When applying as.numeric() to a logical, a double will be returned. NA is a logical value and a logical ...
See Missing values for details. > TRUE & NA [1] NA > FALSE & NA [1] FALSE > TRUE || NA [1] TRUE > FALSE || NA [1] NA

Page 1 of 1