0% found this document useful (0 votes)
2 views53 pages

Introduction To R For Data Analysis

The document is an introduction to R and R Studio for data analysis, highlighting its open-source nature and the various tools available for different types of data. It discusses the advantages of using R, such as no need for a professional programming background and the ability to handle various data forms. Additionally, it provides a brief overview of R's functionalities, including creating vectors, matrices, and data frames, as well as importing and exporting data.

Uploaded by

Drashti Rangwala
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)
2 views53 pages

Introduction To R For Data Analysis

The document is an introduction to R and R Studio for data analysis, highlighting its open-source nature and the various tools available for different types of data. It discusses the advantages of using R, such as no need for a professional programming background and the ability to handle various data forms. Additionally, it provides a brief overview of R's functionalities, including creating vectors, matrices, and data frames, as well as importing and exporting data.

Uploaded by

Drashti Rangwala
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

Introduction to R-

Studio for Data


Analysis
Prof. (Dr.) Prashant Sharma
Professor & Associate Dean
Jindal School of Banking & Finance (JSBF),
O. P. Jindal Global University Sonipat
(Institute of Eminence by Ministry of
Education, GoI)
prashantsharma1989@[Link]
+91-7568799687
Descriptive
analytics: IBM Primary data: Time Series data:

Different Cognos, Tableau,


Power BI
IBM SPSS E-Views

Tools Panel data:


Text data: NVivo,
IBM Watson,
SAS: Proprietary
STATA tool
Available in [Link]

Market Python: Open


R: Open Source
Source

2
Open source, no proprietary license is
required

Developed by Ross Ihaka and Robert


Gentleman

Introduction Appeared for the first time in 1993

to R Large number of researchers and data


scientists are working and updating the r-
packages on regular basis
Companies
using R

7
Companies
using R

8
Companies
using R

9
Companies
using R

10
It is an open-source tool, no proprietary license
required.

Wide range of dedicated packages available for


different functional areas.

Dedicated package available for sectoral requirements

Why to No professional programming background required to


use R for statistical analysis
learn R? Quick availability of newly developed statistical tests
for analysis in R

No limitation in handling different data forms (such as


Cross-sectional, time series, panel, text etc.)
R Studio
This is
script…ignore
time being History &
Environm
ent
comes
This is console. here
You need to type
after
yellow/orange > Plots &
symbol (called Diagrams
cursor prompt) come
and press ENTER here

12
Basics of R

Whatever you
will write after
#, is not a code
(its remark for
you)

13
Type exactly the same as you see after > and ENTER
Play around
with simple
mathematics
like subtract,
divide

R will say
either TRUE
or FALSE

14
Do You want your screen like my screen?

15
16
Typing words

Other than
numbers, you need
to put within
inverted commas,
single or
double….both
works

17
Assign to an object/vector; <- and =
42 is stored in x 100 is stored in y
OR 42 is assigned OR 100 is
to x assigned to y

If you call x, R will If you call y, R will


return/show 42 return/show 100

y/5 is 100/5
x/7 is 42/7
= 20
=6

18
Updating assigned value

No more 42 is
stored in x Omg, error!

19
Functions
sum is a function
(s should be
small)

rep is a function
Observe (r should be
double small)
inverted
commas
sqrt is a function
(s should be
small)

20
Vectors c stands for
concatenation

Same
Why are you result with
writing names three
within inverted styles!
commas?

21
Change in increment & direction
Increment of 0.5

Decrement of 0.5

22
Vector Create a vector
‘learn’ and call it
access

What is there at
2nd, 3rd and 1st
position/location?

Whenever you see a rectangle bracket, it means Sub-setting

23
Replacing
element Let SaS appear
at 3rd place

Call learn

24
Add
Lets add SPSS at 4th
element position

25
Vector
addition

1 is added to each element


of a [1+1 = 2, 2+1 = 3,
3+1 = 4]

Try a/2 and


a*2

26
Vector
Math
a + b=
1+4 = 5; 2+5 = 7; 3+6 = 9

a-b=
1-4 = -3; 2-5 = -3; 3-6 = -3

a*b=
1*4 = 4; 2*5 = 10; 3*6 = 18

27
Single equal to = means ASSIGNMENT
Compare
elements Double equal to,
== means We are asking from R
EQUIVALENCE that whether 1 is at
first position, 99 is at
second position and 3
is at third position

R replies: Yes, it is TRUE that 1 is at first


position; No, 99 is not at second position…in
uncle R’s language FALSE; Yes, it is TRUE that 3
is at third position

28
m is having 5 elements, 4
How to sum digits as 1, 3, 7 & 9 and
one MISSING value (R
with missing reads as NA)

values?

You tried
summing m but
R has thrown
NA (Cant do!)
If you write [Link] = TRUE (Na’s
to be removed in calculation,
Yes!) then you will get 20

29
R helps
you!

30
Lets create matrix is a 1st number will be elements in
Matrix function matrix, 2nd number is number
of ROWS and 3rd number is
number of COLUMNS

R will first fill first


column then next
column…and so on!

31
Storing 1 to 8
Matrix numbers in a Creating a matrix of 2
vector/object name rows and 4 columns
creation sijo name s with
elements stored in
sijo

calling sijo
Column
identification
[ ,c ]
Row
identification
[r, ]

32
4th column,
Matrix ALL rows

Access 2nd Row, ALL


columns 2nd to 4th
column, ALL
rows

2nd row & 4th


column

33
Data Frame We will create
a Data Frame
like this!

34
Numbers with
Variable decimals are
NUMERIC and
Types without decimal
are INTEGERS
Numeric or Integer

Categorical/Factor

Character

35
Create Variables/Vectors

36
Structure of lunch

str is a
function

Type is character (chr), 1 to 5 observations,


sample observations

37
yummy is the A factor variable is shown
new name of [Link] is a with Levels (these are
lunch function mentioned
alphabetically)

Conversion
to factor

Structure is
showing 3
levels (with 3
levels)

38
joy is the Name of
name of variables within
[Link] is a
data frame [Link] (joy)
function

Create
Data Frame

39
Type $ after data frame name (joy)
and you will see all variable names
stored in that data frame

Select name and


press tab key, it
Access will appear after
$ [try with
Data Frame yummy]

40
Names are being
considered as
factor

Access
Data Frame

You can change these to


This is
character by using
numeric
[Link]
[we will discuss this later]

41
Access See double rectangle
Data Frame bracket & variable
number (3rd is yummy)

Try with 1
and 2

42
Access You can write variable name
within double rectangle
Data Frame bracket like “yummy”
(between inverted commas
(single or double)

43
Import
Data Frame

Click From
Text(base)

44
Go to the folder where you have kept
these files

Import
Select infantry and click Open

45
Yes should
be
checked!

Click
Import

46
Command for Path of file
reading file
Name of
file in R

You can see


file in left top
quadrant

47
Import targets

48
Can we merge these two files?

49
Merge

50
After pasting
Export location, you
need to make
Location slashes as shown

Name of file
in R Name of file
Environment going to be
acquired after
export to
location

51
52
Task 1
• Create two CSV files
• One variable should common
• Import these two files in R
• Merge these two files and save it against some object
• Export the merged file into your system

53

You might also like