0% found this document useful (0 votes)
7 views49 pages

R Lang

Uploaded by

niki.p1005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views49 pages

R Lang

Uploaded by

niki.p1005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Introduction to R

Introduction to R

• R is an open-source programming language that is widely used as a


statistical software and data analysis tool.
• It was designed by Ross Ihaka and Robert Gentleman at the
University of Auckland, New Zealand, and is currently developed by
the R Development Core Team
Use of R language

• We use R for Data Science. It gives us a broad variety of libraries


related to statistics.
• It also provides the environment for statistical computing and design.
• R is used by many quantitative analysts as its programming tool. Thus,
it helps in data importing and cleaning.
• R is the most prevalent language. So many data analysts and research
programmers use it. Hence, it is used as a fundamental tool for
finance.
Advantages of R:

• R is the most comprehensive statistical analysis package. As new


technology and concepts often appear first in R.
• As R programming language is an open source. Thus, you can run R
anywhere and at any time.
• R programming language is suitable for GNU/Linux and Windows
operating system.
• R programming is cross-platform which runs on any operating system.
• In R, everyone is welcome to provide new packages, bug fixes, and
code enhancements.
Disadvantages of R:

• In the R programming language, the standard of some packages is less


than perfect.
• Although, R commands give little pressure to memory management.
So R programming language may consume all available memory.
• R programming language is much slower than other programming
languages such as Python and MATLAB.
Assessment Operator
• = (Regular)
• <- (Left)
• -> (Right)

• Var1 = “Simple”
• Var2 <- “left”
• “Right” -> Var 3
Variables
R Data Types
• Numerics: Decimal (floating point values) are part of the numeric
class in R
• Integers: Natural (whole) numbers are known as integers and
are also part of the numeric class
• Logical : Boolean values (True and False) are part of the logical
class. In R these are written in All Caps.
Characters
Comments in R
• Single line comments can be written by using #

• # This single line comment


• # Line 2
• #Line 3

• Multi line comment: “ Your Comment


Line 1 ”
Keywords in R
Keywords in R
• if, else, repeat, while, function, for, in, next and break are used for
control-flow statements and declaring user-defined functions.
• The ones left are used as constants like TRUE/FALSE are used as
boolean constants.
• NaN defines Not a Number value and NULL are used to define an
Undefined value.
Comparison Operators
Arithmetic with R
Addition +
Subtraction -
Division /
Exponents ^
Modulo %%
Vector Basics

• Vectors are one of the key data structures in


• . A vector is a 1 dimensional array that can hold character, numeric, or
logical data elements.
• R will convert the other elements in the array to force everything to
be of the same data type
• We can create a vector by using the combine function c().
• To use the function, we pass in the elements we want in the array,
with each individual element separated by a commom
Vector Names
• The names() function to assign names to each element in our vector.
Vector Indexing and Slicing
Multiple Indexing
Slicing
Indexing with Names
Comparison Operators and Selection
Working with Vectors
Functions with Vectors

https://cran.r-project.org/doc/contrib/Short-refcard.pdf
Vector Comparisons

• v <- c(1,2,3,4,5)
• v <- 2
TRUE FALSE FALSE FALSE FALSE
• v == 3
• FALSE FALSE TRUE FALSE FALSE
Creating a Matrix
Creating Matrices from Vectors
Naming Matrices
Matrix Selection and Indexing
Matrix Arithmetic
Matrix Arithmetic with multiple matrices
Matrix multiplication
Matrix Operations
Binding columns and rows

You might also like