Simran R Programming File
Simran R Programming File
Installation:
Step-1: Open the web browser and Search https://cran.r-project.org/bin/windows/base/.
Step-2: Click on the Download R link for windows on the left-hand side of the page.
Step-3: Once the download is complete, run the installer and follow the prompts to install R on your computer.
Step-4: After the installation is complete, you can launch R by clicking on the R icon in your applications folder or
start menu.
Problems:
Problem-1:
The weights of five people before and after a diet programme are given in the table:
Read the ‘before’ and ‘after’ values into two different vectors called before and after. Use R to evaluate the amount of
weight lost for each participant. What is the average amount of weight lost?
Solution:
Problem-2:
How would you write a function equivalent to sum((x-mean(x))^2) in a language like C or Java?
Problem-3:
Create the following vectors in R using seq() and rep() :
Solution:
Problem-4:
Solution:
EXPERIMENT NO. 2
AIM – Subsetting, logical operations, matrices and lists in R
Theory:
Subsetting :- In R Programming Language, subsetting allows the user to access elements from an object. It
takes out a portion from the object based on the condition provided. In R, indexing starts from 1.
Logical Operator :- The Logical operators in R programming are used to combine two or more conditions,
and perform the logical operations using & (Logical AND), | (Logical OR) and ! (Logical NOT).
Matrices :- A matrix is a two dimensional data set with columns and rows. A column is a vertical
representation of data, while a row is a horizontal representation of data. A matrix can be created with the
matrix() function. Specify the nrow and ncol parameters to get the amount of rows and columns.
Lists:- Lists are the R objects which contain elements of different types like − numbers, strings, vectors and
another list inside it. A list can also contain a matrix or a function as its elements. List is created using the
list() function.
Problems:
Problem-1:
The built-in vector LETTERS contains the uppercase letters of the alphabet. Produce a vector of (i) the first 12 letters;
(ii) the odd ‘numbered’ letters; (iii) the English consonants.
Problem-2:
The function rnorm() generates normal random variables. For instance, rnorm(10) gives a vector of 10 i.i.d. standard
normals. Generate 20 standard normals, and store them in x. Then obtain subvectors of
(i) the entries in x which are less than 1;
(ii) the entries between -½ and 1;
(iii) the entries whose absolute value is larger than 1.5.
Problem-3:
Construct the matrix:
Show that B×B×B is a scalar multiple of the identity matrix and find the scalar.
Problem-4:
Construct the following matrices:
(i)
(ii)
(iii)
(iv)
(v)
(vi)
Problem-5:
Solve the following system of simultaneous equations using matrix methods: