Quick Contact


    R Variables

    Variables are used for storing data where that value can be altered based to your need. Unique name has to be given to variable (also for functions and objects) is identifier.

    Rules for writing Identifiers in R

    Identifier names are a combination of alphabets, digits, period (.) and also underscore (_). It is mandatory to start an identifier with a letter or a period. Another thing is if it starts with a period / dot operator then it you cannot write digit following it. Here are some of the points other than that which you should remember before naming any identifier:

    • Reserved words in R cannot be used as identifiers.
    • Valid identifiers in R are:
    • total, Sum, .work.with, this_is_accepted, Num6

    • Invalid identifiers in R:
    • t0t@l, 5um, _ray, TRUE, .0n3

    Constants in R

    Constants are entities within a program whose value can’t be changed. There are 2 basic types of constant. These are numeric constants and character constants.

    Numeric Constants

    All the numbers you will be using within a program fall under this category. There are sub types like integer, double or complex, which is checked usng typeof() function. Example:

    typeof (6)

    [1] “double”

    > typeof (4L)

    [1] “integer”

    Character Constants

    These can be signified by means of either single quotes (‘) or using double quotes (“) as delimiters.

    ‘ray’

    [1] “ray”

    > typeof(“karlos”)

    [1] “character”

    Vectors in R programming

    So far, you have used the colon operator in previous chapter, to create series from one number to another, the c function used for concatenating different values and vectors for creating longer vectors.

    Let’s recall the statements back:

    	8.4:4.6       #sequence of numbers from 8.4 down to 4.6
    	## [1] 8.5 7.5 6.5 5.5 4.5
    	c (1, 1:3, c (5, 8), 13)       #values concatenated into single vector
    	## [1] 1 1 2 3 5 8 13
    	

    The vector function is used to create a vector of a fixed type and length. Every value has the result as zero, FALSE or any null string or something that is equivalent of “nothing”. Here is a list of examples:

    vector (“numeric”, 4)

    ## [1] 0 0 0 0

    vector (“complex”, 4)

    ## [1] 0+0i 0+0i 0+0i 0+0i

    vector (“logical”, 4)

    ## [1] FALSE FALSE FALSE FALSE

    vector (“character”, 4)

    ## [1] “” “” “” “”

    Copyright 1999- Ducat Creative, All rights reserved.