Page 212 - Data Science class 11
P. 212

3.  my var <- "  Sapna"

                Because is a space in between two words.
             4.  _my_var <- "  Sapna"

                Because it starts with underscore. See rule 1.
             5.  my_v@ar <- "  Sapna"

                Because it contains a special character @.
             6.  TRUE <- "  Sapna"

                Because it is a reserved word.
             7.  var_name%
                Invalid because it contains the character ‘%’. Only dot(.) and underscore allowed.
             8.  2var_name

                Invalid as it starts with a number
             9.  .2var_name
                Invalid as the starting dot is followed by a number.
             10.  _var_name

                Invalid as it starts with _ which is not valid.

        6.5 oBjects in r Programming

        In contrast to other programming languages like C and  Java, in R,  the variables are not declared as some data type.
        The variables are assigned as R-objects and the data type of the R-object becomes the data type of the variable. There
        are many types of R-objects. The most frequently used ones are:

           • Vectors
           • Lists

           • Matrices
           • Arrays
           • Factors
           • Data Frames

        You will be introduced to all these objects a little later.
        The simplest of these objects is the vector object.


        6.6 Vectors

        Vectors are the most basic data objects. A vector is a basic data structure that plays an important role in R programming.
        In R, a sequence of elements that share the same data type is known as a vector. A vector is a combination of multiple
        values (numeric, character, or logical) in the same object. In this case, you can have numeric vectors, character
        vectors, or logical vectors.

        The R manual defines a vector as "a single entity consisting of a collection of things." A collection of numbers, for
        example, is a numeric vector—the first five integer numbers form a numeric vector of length 5.






          210   Touchpad Data Science-XI
   207   208   209   210   211   212   213   214   215   216   217