Statistical Analysis: an Introduction using R/R/Logical operations

When accessing elements of vectors, we saw how to use a simple logical expression involving the less than sign to produce a logical vector, which could then be used to select elements less than a certain value. This type of logical operation is very useful thing to be able to do. As well as, there are a handful of other comparison operators. Here is the full set (See  for more details) Even more flexibility can be gained by combining logical vectors using and, or, and not. For example, we might want to identify which US states have an area less than 10 000 or greater than 100 000 square miles, or to identify which have an area greater than 100 000 square miles and which have a short name. The code below shows how can be used to do this, using the following R symbols: When using logical vectors, the following functions are particularly useful, as illustrated below
 * (less than) and  (less than or equal to)
 * (greater than) and  (greater than or equal to)
 * (equal to ) and  (not equal to)
 * ("and")
 * ("or")
 * ("not")
 * identifies which elements of a logical vector are
 * can be used to give the number of elements of a logical vector which are . This is because   forces its input to be converted to numbers, and if TRUE and FALSE are converted to numbers, they take the values 1 and 0 respectively.
 * returns different values depending on whether each element of a logical vector is TRUE or FALSE. Specifically, a command such as  takes   and returns, for each element that is , the corresponding element from  , and for each element that is  , the corresponding element from  . An extra elaboration is that if   or   are shorter than   they are extended by duplication to the correct length.