You are on page 1of 9

Shrishti Tiwari

139
BE Comps B3

Experiment 8

Title :- Exploring features of R

Aim :- R Programming Basics

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, Python, or
FORTRAN languages for efficiency.

Exploring the features of R


R is a programming language and software environment for statistical analysis, graphics
representation, and reporting.
The following are the essential features of R :-
● R is a well-developed, simple and effective programming language that includes conditionals,
loops, user-defined recursive functions, and input and output facilities.
● R has an effective data handling and storage facility,
● R provides a suite of operators for calculations on arrays, lists, vectors, and 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 computer or by
printing the papers.
Exploring RGUI
RGUI stands for the Graphical User interface for R Programming
Advantages of RGUI
● Ease of Use
● General Usability
● Graphics
● Analytics
RGUI, the standard R user interface, is a simple interface to the R language, with some
menus and toolbars, as well as a number of windows; when you start R, the Console
window is displayed. The available menus (and toolbars) are limited to general
housekeeping tasks; for the analytical study, you will have to type R commands
(functions), e.g.. to produce a histogram of a variable named urb you will have to type
hist(urb) at the command prompt (>). in the console window

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 name starts with a letter or the dot not
followed by a number.
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
with the help of the typeof() function.

Exporting data to a text file


One of the important formats to store a file is in a text file. R provides various methods that one can export data
to a text file.
● write.table(): The R base function write.table() can be used to export a data frame or a matrix to a
text file.
Syntax:
write.table(x, file, append = FALSE, sep = ” “, dec = “.”, row.names = TRUE,
col.names = TRUE)
Parameters:
x: a matrix or a data frame to be written.
file: a character specifying the name of the result file.
sep: the field separator string, e.g., sep = “\t” (for tab-separated value).
dec: the string to be used as decimal separator. Default is “.”
row.names: either a logical value indicating whether the row names of x are to be written along
with x, or a character vector of row names to be written.
col.names: either a logical value indicating whether the column names of x are to be written along
with x, or a character vector of column names to be written. Manipulating and processing data in
R
Data structures provide the way to represent data in data analytics. We can manipulate data in R
for analysis and visualization.
One of the most important aspects of computing with data in R is its ability to manipulate data and enable its
subsequent analysis and visualization. Let us see few basic data structures in R: a. Vectors in R
These are ordered containers of primitive elements and are used for 1-dimensional data. Types –
integer, numeric, logical, character, complex
b. Matrices in R

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.

You might also like