Vectorized Operations & Functions:

1. Replicate Function in R:

Rep() is the function in R that replicates the values as per the argument passed.

in the above example Sri is the string and 3 is the argument Passed.

The Output printed in console is “sri” “sri” sri’ , as the argument passed is 3 so the Value is printed thrice.

2. How to Access particular Element in a vector ??????

As from this above example : Vector is created with 4 names and that vector is assigned to xyz variable

I want the fourth Value from the vector so the syntax incorporated is xyz[4], The output printed in Console pane is “Krupa, which is our Fourth Name from the vector.

3. I don’t want to Access particular Element in a vector

If I don’t want the second Value from the vector so the syntax incorporated is xyz[-2], The output printed in Console pane is “Jo” “Mahesh” “Krupa”, The second Name “sri is ignored.

If I want only first three Values from Vector, then the syntax will be Like : xyz[1:3], then it will Print “Joe” “sri “Mahesh”

If I want only first and Fourth Values from Vector, then the syntax will be Like : xyz[1,4], then it will Print “Joe” “Krupa”

4. vector Arithmetic’s :

Let’s Perform Arithmetic operations of vectors :

Adding two vectors : 
For example, suppose we have two vectors a and b.
 a = c(1, 3, 5, 7) 
 b = c(1, 2, 4, 8)
if we add a and b together, the sum would be a vector whose members are the sum of the corresponding members from a and b.
The Output will Be : 2  5  9 15, similarly we can perform  Subtraction between  Vectors, Division between vectors, Product between vectors and comparison between vectors (greater than ,less than... etc.) 

As we can see the result in console pane is 2 5 9 15

5.Recycling  Concept in Vectors:

If two vectors are of unequal length, the shorter one will be recycled in order to match the longer vector. For example, the below vectors have different lengths, and their sum is computed by recycling values of the shorter vector .

6. rnorm( ) Function : (Normal distribution)

Before diving deep into the concept of rnorm() function, let us understand few things about the Normal Distribution of data.

To begin with, data distribution helps us understand the variation of the data and its values with respect to the factors. Normal distribution has the data distributed normally i.e. it follows a uniform (bell-curved shaped) segregation of data. It happens to have the mean value as 1 and standard variance as constant.

Look at the below Curve, the data is symmetrical with a single central peak at the mean (average) of the data. Fifty percent of the distribution lies to the left of the mean and fifty percent lies to the right of the mean. Such graphs are called Bell Curve

Syntax:

rnorm(num, mean, variance)

We need to provide the rnorm() function with the number of values that needs to be generated. Further, the mean and variance values are optional. If not provided, it takes the default values as mean = 0 and variance = 1.

With rnorm() function, we can generate random numbers that follow normal distribution of data at ease. Unlike other functions, rnorm() function provides us with the facility to customize the value of mean and variance accordingly.

Let’s Take a small example :

From the above lines of code, Value 5 is assigned to variable xyz, and the Five random Numbers are printed