Page 214 - Data Science class 11
P. 214

6.6.3 operators for Vectors
        As shown below, there are four main categories of operators in the R programming language:



        •   Arithmetic operators        +      -      *      /    %%     %/%     ^


        •   Relational operators        <      >     ==     <=    >=      !=


        •   Logical operators           &      |      !     &&     ||



        •   Assignment operators        =     <-     ->    <<-    ->>


        We will discuss them in detail.

        a.  Arithmetic Operators for Vectors
        The R language supports the arithmetic operators. The operators act on each element of the vector individually.
             1.  +  Plus operator adds two vectors
        Example
        Enter the following code snippet:

             first <- c( 3,7.5,12)
             second  <- c(7, 4, 5)
             print(first+ second)
        The following result is produced:























             2.  − Minus operator subtracts the second vector from the first

        Example
        Enter the following code snippet:

             first <- c( 3,7.5,12)
             second  <- c(7, 4, 5)
             print(first- second)






          212   Touchpad Data Science-XI
   209   210   211   212   213   214   215   216   217   218   219