Professional Documents
Culture Documents
Nidhi Yadav Exp 8 Bda
Nidhi Yadav Exp 8 Bda
148
BE Comps B3
Experiment 8
Theory :-
R is a programming language and software environment for statistical analysis, graphics
representation, and reporting. R was created by Ross Ihaka and Robert Gentleman at the University
of Auckland, New Zealand, and is currently developed by the R Development Core Team.
The core of R is an interpreted computer language that allows branching and looping and modular
programming using functions. R allows integration with the procedures written in the C, C++, .Net,
facilities.
matrices.
● R provides a large, coherent, and integrated collection of tools for data analysis. ●
R provides graphical facilities for data analysis and display either directly at the
Exploring R Studio
RStudio is an integrated development environment for R, a programming language for statistical
computing and graphics. It is available in two formats: RStudio Desktop is a regular desktop
application while RStudio Server runs on a remote server and allows accessing RStudio using a
web browser.
It can also be defined as an integrated development environment(IDE) for R. IDE is a GUI, where
you can write your quotes, see the results and also see the variables that are generated
during the course of programming.
● R Studio is available as both Open source and Commercial software.
● R Studio is also available as both Desktop and Server versions.
● R Studio is also available for various platforms such as Windows, Linux, and macOS.
● The console
panel(left panel) is the place where R is waiting for you to tell it what to do, and see the results
that are generated when you type in the commands.
● To the top right, you have the Environmental/History panel. It contains 2 tabs: ○
Environment tab: It shows the variables that are generated during the course of
programming in a workspace that is temporary.
○ History tab: In this tab, you’ll see all the commands that are used till now from the
start of usage of R Studio.
Variables in R
A variable provides us with named storage that our programs can manipulate. A variable in R
can store an atomic vector, a group of atomic vectors or a combination of many Robjects. A valid
variable name consists of letters, numbers and the dot or underline characters. The variable
Variable Assignment
The variables can be assigned values using leftward, rightward and equal to operator. The values of
the variables can be printed using print() or cat() function. The cat() function combines multiple
items into a continuous print output.
Working with Vectors
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
supports logical, integer, double, character, complex, or raw data type. The elements which are
contained in vectors are known as components of the vector. We can check the type of vector
These are Rectangular collections of elements and are useful when all data is of a single class that
is numeric or characters.
Dimensions – two, three, etc.
c. Lists in R
These are ordered containers for arbitrary elements and are used for higher dimension data, like
customer data information of an organization. When data cannot be represented as an array or a
data frame, a list is the best choice. This is so because lists can contain all kinds of other
objects,
including other lists or data frames, and in that sense, they are very flexible. d.
Data frames
These are two-dimensional containers for records and variables and are used for representing
data from spreadsheets etc. It is similar to a single table in the database. Creating Subsets of Data
in R
As we know, data size is increasing exponentially and doing analysis on complete data is very
time-consuming. So data is divided into small sized samples and analysis of samples is done. The
process of creating samples is called subsetting.
Different methods of subsetting in R are:
a. $
The dollar sign operator selects a single element of data. When you use this operator with a
data
frame, the result is always a vector.
b. [[
Similar to $ in R, the double square brackets operator in R also returns a single element, but it
offers the flexibility of referring to the elements by position rather than by name. It can be used for
data frames and lists.
c. [
The single square bracket operator in R returns multiple elements of data. The index within the
square brackets can be a numeric vector, a logical vector, or a character vector. For example:
To retrieve 5 rows and all columns of already built in data set iris, below command is
used:
1 > iris[1:5, ]
# Question 1:
#Question 2:
#Question 3
#Question 4
#Question 5
5.b)
#Question 6)
Conclusion :- We have seen the basic programs in R Program.