Introduction To R
Introduction To R
Introduction To R
What is R programming?
Data scientist
Statistician
Data analyst
R Programmer
Business Analyst
Companies using R
Features Of R
R is a language and
Python is a general-
environment for
purpose programming
statistical programming
Introduction language for data
which includes
analysis and scientific
statistical computing
computing
and graphics.
It can be used to
It has many features develop GUI
which are useful for applications and web
Objective
statistical analysis and applications as well as
representation. with embedded
systems
Some essential
There are many
Libraries and packages and libraries
packages and libraries
packages are Pandas, Numpy, Sc
like ggplot2, caret, etc.
ipy, etc.
It takes a more
It is mainly used for
streamlined approach
Scope complex data analysis
for data science
in data science.
projects.
R vs Python
Advantages of R
Variables are used to store data with named locations that your programs can
manipulate
A variable can be a combination of letters, digits, period and underscore. No other
special character is allowed
A valid variable name consists of a combination of alphabets, numbers, dot(.), and
underscore(_) characters. Example: var.1_ is valid
Apart from the dot and underscore operators, no other special character is allowed.
Example: var$1 or var#1 both are invalid
Variables can start with alphabets or dot characters. Example: .var or var is valid
The variable should not start with numbers or underscore. Example: 2var or _var is invalid.
If a variable starts with a dot the next thing after the dot cannot be a number. Example:
.3var is invalid
The variable name should not be a reserved keyword in R. Example: TRUE, FALSE,etc.
Variables in R
= (Simple Assignment)
<- (Leftward Assignment)
-> (Rightward Assignment)
Important Methods for R Variables
class() function
is used to determine the data type of the variable provided to it.
ls() function
is used to know all the present variables in the workspace.
rm() function
is used to delete an unwanted variable within your workspace.
Operators
Arithmetic Operators
Addition
Substraction
Multiplication
Division
Remainder / mod
Exponent
Order of operatios
Paranthesis
Exponent (^)
Multiplication and division (left to rigth)
Addition and substractions (left to rigth)
Rational / Logical Operators
Taking multiple inputs in R language is same as taking single input, just need to
define multiple readline() for inputs.
Syntax:
var1 = readline(“Enter 1st number : “);
var2 = readline(“Enter 2nd number : “);
var3 = readline(“Enter 3rd number : “);
var4 = readline(“Enter 4th number : “);
or,
{
var1 = readline(“Enter 1st number : “);
var2 = readline(“Enter 2nd number : “);
var3 = readline(“Enter 3rd number : “);
var4 = readline(“Enter 4th number : “);
}
Taking String and Character input in R
In order to prompt the user, prompt keyword can be used with in the
readline method
E.g. var1 = readline(prompt = “Enter any number : “);
To take string input
Syntax:
string:
var1 = readline(prompt = “Enter your name : “);
character:
var1 = readline(prompt = “Enter any character : “);
var1 = as.character(var1)
Execution of an R file