0% found this document useful (0 votes)
53 views

Introduction To R Programming

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Introduction To R Programming

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Introduction to R programming

• The R programming language is an open-source scripting language


for predictive analytics and data visualization.
• The initial version of R was released in 1995 to allow academic
statisticians and others with sophisticated programming skills to
perform complex data statistical analysis and display the results in
any of a multitude of visual graphics.
• The "R" name is derived from the first letter of the names of its two
developers, Ross Ihaka and Robert Gentleman, who were
associated with the University of Auckland at the time.
• R is a powerful tool for statistics, graphics, and statistical programming.
• It is used by tens of thousands of people daily to perform serious statistical analyses.
• It is a free, open source system whose implementation is the collective accomplishment
of many intelligent, hard-working people. There are more than 2,000 available add-ons,
and R is a serious rival to all commercial statistical packages
The R software environment
• The R language programming environment is built around a standard
command-line interface. Users leverage this to read data and load it to the
workspace, specify commands and receive results. Commands can be
anything from simple mathematical operators, including +, -, * and /, to
more complicated functions that perform linear regressions and other
advanced calculations.
• Users can also write their own functions.
• The environment allows users to combine individual operations,
Ex: Such as joining separate data files into a single document,
1. What is R? and Data Types

a. Download, Install, Configure


b. Learn to use help() function
c. Understand data types in R (logical,numeric,etc)
d. Convert datatypes
2. Getting Data In and Out of R
a. Create, find, and remove data(vector, matrix, data frame) in R
b. Read external data into R(.txt,.csv)
c. Write R data into external files(.txt,.csv)
R Help: and ?

The help() function and ? help operator in R provide access to the documentation pages
for R functions, data sets, and other objects, both for packages in the standard R
distribution and for contributed packages.
To access documentation for the standard lm (linear model) function, for example, enter
the command help(lm) or help("lm"), or ?lm or ?"lm" (i.e., the quotes are optional).
To access help for a function in a package that’s not currently loaded, specify in
addition the name of the package:
For example, to obtain documentation for the rlm() (robust linear model)
function in the MASS package, help(rlm, package="MASS").
Creating Variables in R
Variables are containers for storing data values.
R does not have a command for declaring a variable.
A variable is created the moment you first assign a value to it.
To assign a value to a variable, use the <- sign.
To output (or print) the variable value, just type the variable name
Variable Names
• A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume).
• Rules for R variables are:
i) A variable name must start with a letter and can be a combination of letters, digits,
period(.) and underscore(_). Ex: vn_4
If it starts with period(.), it cannot be followed by a digit.
ii) A variable name cannot start with a number or underscore (_)
iii) Variable names are case-sensitive (age, Age and AGE are three different variables)
iv) Reserved words cannot be used as variables (TRUE, FALSE, NULL, if...)
Basic Data Types in R
• Variables can store data of different types, and different types can do different things.

R has a variety of data types and object classes.


Basic data types in R can be divided into the following types:
• numeric - (10.5, 55, 787)
• integer - (1L, 55L, 100L, where the letter "L" declares this as an integer)
• complex - (9 + 3i, where "i" is the imaginary part)
• character (string) - ("k", "R is exciting", "FALSE", "11.5")
• logical (boolean) - (TRUE or FALSE)
class() function can be used to check the data type of a variable
• An operator is a symbol that tells the compiler to
perform specific mathematical or logical
manipulations. R language is rich in built-in operators
and provides following types of operators.
Types of Operators
• Arithmetic Operators
R operators • Relational Operators
• Logical Operators
• Assignment Operators
• Miscellaneous Operators
Sometimes to analyze data using R, it requires to
convert data into another data type.

R has various conversion functions that are used to


convert the data type.

In R, Conversion Function are of two types:

Conversion Functions for Data Types

Conversion Functions for Data


Structures
Conversion Functions For Data Types
There are various conversion functions available for Data
Types. These are:
•as.numeric()Decimal value known numeric values in R.
• It is the default data type for real numbers in R. In
R as.numeric() converts any values into numeric values.
Syntax:
• Syntax: as.logical(value)
• Syntax: as.character(value)
• Syntax: as.numeric(value)
• Syntax: rbind(vector1, vector2, vector3…..vectorN)
• Syntax: cbind(vector1, vector2, vector3…..vectorN)
• Syntax: data.frame(vector1, vector2, vector3…..vectorN)

You might also like