SlideShare a Scribd company logo
1 of 23
A Brief Introduction to R
Dr. Sachita Yadav
Associate Professor
Management Department
R, And the Rise of
the Best Software
Money Can’t Buy
R programming
language is a lot
like magic...
except instead of
spells you have
functions.
=
muggle
Like muggles, users of traditional stats software packages are
limited in their ability to change their environment. They have to
rely on algorithms that have been developed for them. The way
they approach a problem is constrained by how employed
programmers thought to approach them. And they have to pay
money to use these constraining algorithms.
=
wizard
R users are like wizards. They can rely on functions developed
for them by statistical researchers, but they can also create their
own. They don’t have to pay for the use of them, and once
experienced enough, they are almost unlimited in their ability to
change their environment.
R
Advantages Disadvantages
oNot user friendly at start - steep
learning curve.
oEasy to make mistakes
oWorking with large datasets is
difficult.
oFast and free
oAccess to R available whenever and
wherever need
oR packages
oR helps you think about data in ways
that are useful for statistical analysis
oR produces excellent, publication-
quality graphics
oR promotes reproducible (edited,
rerun, shared, commented) research.
oR is up-to-date
Learning R....
There are over 2000 add-on packages
 This is an enormous advantage - new techniques available without
delay, and they can be performed using the R language.
 Allows you to build a customized statistical program suited to your
own needs.
 Downside = as the number of packages grows, it is becoming difficult
to choose the best package for your needs, & QC is an issue.
8
 R sessions are interactive
Getting Started
To Install Rstudio
Go to www.rstudio.com and click on the "Download RStudio"
button.
Click on "Download RStudio Desktop."
Click on the version recommended for your system, or the
latest Windows version, and save the executable file. Run the
.exe file and follow the installation instructions.
Installing Packages
 Install the packages (Optional)
 Run R studio.
 Click on the Packages tab in the bottom-right
section and then click on install. The following
dialog box will appear.
 In the Install Packages dialog, write the package
name you want to install under the Packages
field and then click install.
Installing Packages 12
Operation Symbols
Symbol Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
%%
Modulo (estimates remainder in a
division)
^ Exponential
Objects in R
 Objects in R obtain values by assignment.
 This is achieved by the gets arrow, <-, and not the
equal sign, =.
 Objects can be of different kinds.
Built in Functions
 R has many built in functions that compute
different statistical procedures.
 Functions in R are followed by ( ).
 Inside the parenthesis we write the object (vector,
matrix, array, dataframe) to which we want to
apply the function.
Vectors
The very basic data types are the R-objects called vectors
Vectors are variables with one or more values of the same type.
When you want to create vector with more than one element, you should
use c() function which means to combine the elements into a vector.
# Create a vector.
apple <- c('red','green',"yellow")
print(apple)
# Get the class of the vector
print(class(apple))
When we execute the above code, it produces the following result −
[1] "red" "green" "yellow"
[1] "character"
Data Frame
 Researchers work mostly with data frames
 With previous knowledge you can built data frames in R
 Also, import data frames into R.
 Data frames are tabular data objects
Data Frames are created using the data.frame() function.
# Create the data frame.
BMI <- data.frame(gender = c("Male", "Male","Female"), height = c(152, 171.5, 165),
weight = c(81,93, 78),Age = c(42,38,26))
#print(BMI)
When we execute the above code, it produces the following result −
gender height weight Age
1 Male 152.0 81 42
2 Male 171.5 93 38
3 Female 165.0 78 26
Practice
 A<-(“Welcome”) then press control R
 x<-c(3,4,5,6)
 Y<-c(3,4,5,6)
 x+y run the command and get result
To check data type
a<-4 run data
Command is # Class(a) and run R to get result
Practical Example- Rainfall Zone
 setwd("D:")
 rain<-read.csv("rainfall_zonewise.CSV",header=TRUE)
 fix(rain)
 rain<-read.csv("rainfall_zonewise.CSV",header=TRUE)
 dim(rain)
 names(rain)
 rain1<-rain[,c(1,2,4,384:386)]
 fix(rain1)
 dim(rain1)
#average rainfall for last 65 years
 levels(rain1$DISTRICT)
 rain.dist<-
aggregate(rain1$ANNUAL,by=list(rain1$DISTRICT),FUN=mean)
 fix(rain.dist)
19
 rain.zone<-aggregate(rain1$ANNUAL,by=list(rain1$ZONE),FUN=mean)
 fix(rain.zone)
 names(rain1)
 levels(rain1$DISTRICT)
 bkl<-rain1[rain1$DISTRICT=="BAGALKOTE",]
 fix(bkl)
 plot(rain1$ANNUAL)
 plot(bkl$ANNUAL)
 plot(bkl$ANNUAL,type="l")
 barplot(bkl$ANNUAL)
 plot(bkl$YEAR,bkl$ANNUAL,type="l")
 plot(bkl$YEAR,bkl$ANNUAL,type="l",main="rainfall trend in
bagalkot",xlab="YEAR",ylab="RAINFALL",col="green",lwd=3)
 barplot(bkl$YEAR,bkl$ANNUAL,type="l",main="rainfall trend in
bagalkot",xlab="YEAR",ylab="RAINFALL",col="green",lwd=3)
20
 blr<-rain1[rain1$DISTRICT=="BENGALURU RURAL",]
 fix(blr)
 plot(rain1$ANNUAL)
 plot(blr$ANNUAL)
 plot(blr$ANNUAL,type="l")
 barplot(blr$ANNUAL)
 plot(blr$YEAR,blr$ANNUAL,type="l")
 plot(blr$YEAR,blr$ANNUAL,type="l",main="rainfall trend in bengaluru
rural",xlab="YEAR",ylab="RAINFALL",col="green",lwd=3)
 barplot(bkl$YEAR,bkl$ANNUAL,type="l",main="rainfall trend in
bagalkot",xlab="YEAR",ylab="RAINFALL",col="green",lwd=3)
 par(mfrow=c(2,1))
 plot(blr$YEAR,blr$ANNUAL,type="l",main="rainfall trend in bengaluru
rural",xlab="YEAR",ylab="RAINFALL",col="green",lwd=3)
 fit<-lm(ANNUAL ~ YEAR,data=bkl)
 summary(fit)
 abline(fit)
 abline(fit,col="blue",lwd=3)
 plot(bkl$YEAR,bkl$ANNUAL,type="l",main="rainfall trend in
bagalkot",xlab="YEAR",ylab="RAINFALL",col="green",lwd=3)
21
Learning R
 Because R is interactive, errors are your friends!
 MOST IMPORTANT - the more time we spend using R, the
more comfortable we become with it. After doing our first
real project in R, we won’t look back.
Thank you for your time!!

More Related Content

Similar to Basics of R

STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdfSTAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdfSOUMIQUE AHAMED
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfKabilaArun
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfattalurilalitha
 
Best corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbaiBest corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbaiUnmesh Baile
 
An introduction to R is a document useful
An introduction to R is a document usefulAn introduction to R is a document useful
An introduction to R is a document usefulssuser3c3f88
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R langsenthil0809
 
Data analysis in R
Data analysis in RData analysis in R
Data analysis in RAndrew Lowe
 
GET STARTED WITH R FOR DATA SCIENCE
GET STARTED WITH R FOR DATA SCIENCEGET STARTED WITH R FOR DATA SCIENCE
GET STARTED WITH R FOR DATA SCIENCEUSDSI
 
Up your data game: How to use R to wrangle, analyze, and visualize data faste...
Up your data game: How to use R to wrangle, analyze, and visualize data faste...Up your data game: How to use R to wrangle, analyze, and visualize data faste...
Up your data game: How to use R to wrangle, analyze, and visualize data faste...Charles Guedenet
 
Reproducibility with R
Reproducibility with RReproducibility with R
Reproducibility with RMartin Jung
 
Presentation on use of r statistics
Presentation on use of r statisticsPresentation on use of r statistics
Presentation on use of r statisticsKrishna Dhakal
 
Sas Enterprise Guide A Revolutionary Tool
Sas Enterprise Guide A Revolutionary ToolSas Enterprise Guide A Revolutionary Tool
Sas Enterprise Guide A Revolutionary Toolsysseminar
 
software engineering modules iii & iv.pptx
software engineering  modules iii & iv.pptxsoftware engineering  modules iii & iv.pptx
software engineering modules iii & iv.pptxrani marri
 
Unit 2 - Data Manipulation with R.pptx
Unit 2 - Data Manipulation with R.pptxUnit 2 - Data Manipulation with R.pptx
Unit 2 - Data Manipulation with R.pptxMalla Reddy University
 
Implementing a data_science_project (Python Version)_part1
Implementing a data_science_project (Python Version)_part1Implementing a data_science_project (Python Version)_part1
Implementing a data_science_project (Python Version)_part1Dr Sulaimon Afolabi
 

Similar to Basics of R (20)

STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdfSTAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
R-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdfR-Language-Lab-Manual-lab-1.pdf
R-Language-Lab-Manual-lab-1.pdf
 
Best corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbaiBest corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbai
 
An introduction to R is a document useful
An introduction to R is a document usefulAn introduction to R is a document useful
An introduction to R is a document useful
 
Get started with R lang
Get started with R langGet started with R lang
Get started with R lang
 
Data analysis in R
Data analysis in RData analysis in R
Data analysis in R
 
R decision tree
R   decision treeR   decision tree
R decision tree
 
GET STARTED WITH R FOR DATA SCIENCE
GET STARTED WITH R FOR DATA SCIENCEGET STARTED WITH R FOR DATA SCIENCE
GET STARTED WITH R FOR DATA SCIENCE
 
Up your data game: How to use R to wrangle, analyze, and visualize data faste...
Up your data game: How to use R to wrangle, analyze, and visualize data faste...Up your data game: How to use R to wrangle, analyze, and visualize data faste...
Up your data game: How to use R to wrangle, analyze, and visualize data faste...
 
Lecture_R.ppt
Lecture_R.pptLecture_R.ppt
Lecture_R.ppt
 
Reproducibility with R
Reproducibility with RReproducibility with R
Reproducibility with R
 
Presentation on use of r statistics
Presentation on use of r statisticsPresentation on use of r statistics
Presentation on use of r statistics
 
Sas Enterprise Guide A Revolutionary Tool
Sas Enterprise Guide A Revolutionary ToolSas Enterprise Guide A Revolutionary Tool
Sas Enterprise Guide A Revolutionary Tool
 
software engineering modules iii & iv.pptx
software engineering  modules iii & iv.pptxsoftware engineering  modules iii & iv.pptx
software engineering modules iii & iv.pptx
 
R studio
R studio R studio
R studio
 
Unit 2 - Data Manipulation with R.pptx
Unit 2 - Data Manipulation with R.pptxUnit 2 - Data Manipulation with R.pptx
Unit 2 - Data Manipulation with R.pptx
 
"r" for ROI
"r" for ROI"r" for ROI
"r" for ROI
 
Implementing a data_science_project (Python Version)_part1
Implementing a data_science_project (Python Version)_part1Implementing a data_science_project (Python Version)_part1
Implementing a data_science_project (Python Version)_part1
 

Recently uploaded

VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Callshivangimorya083
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceSapana Sha
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxFurkanTasci3
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一F La
 
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptxAmazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptxAbdelrhman abooda
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 

Recently uploaded (20)

VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
꧁❤ Greater Noida Call Girls Delhi ❤꧂ 9711199171 ☎️ Hard And Sexy Vip Call
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts Service
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptx
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
 
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptxAmazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
Amazon TQM (2) Amazon TQM (2)Amazon TQM (2).pptx
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 

Basics of R

  • 1. A Brief Introduction to R Dr. Sachita Yadav Associate Professor Management Department
  • 2. R, And the Rise of the Best Software Money Can’t Buy R programming language is a lot like magic... except instead of spells you have functions.
  • 3. = muggle Like muggles, users of traditional stats software packages are limited in their ability to change their environment. They have to rely on algorithms that have been developed for them. The way they approach a problem is constrained by how employed programmers thought to approach them. And they have to pay money to use these constraining algorithms.
  • 4. = wizard R users are like wizards. They can rely on functions developed for them by statistical researchers, but they can also create their own. They don’t have to pay for the use of them, and once experienced enough, they are almost unlimited in their ability to change their environment.
  • 5. R Advantages Disadvantages oNot user friendly at start - steep learning curve. oEasy to make mistakes oWorking with large datasets is difficult. oFast and free oAccess to R available whenever and wherever need oR packages oR helps you think about data in ways that are useful for statistical analysis oR produces excellent, publication- quality graphics oR promotes reproducible (edited, rerun, shared, commented) research. oR is up-to-date
  • 7. There are over 2000 add-on packages  This is an enormous advantage - new techniques available without delay, and they can be performed using the R language.  Allows you to build a customized statistical program suited to your own needs.  Downside = as the number of packages grows, it is becoming difficult to choose the best package for your needs, & QC is an issue.
  • 8. 8
  • 9.  R sessions are interactive
  • 10. Getting Started To Install Rstudio Go to www.rstudio.com and click on the "Download RStudio" button. Click on "Download RStudio Desktop." Click on the version recommended for your system, or the latest Windows version, and save the executable file. Run the .exe file and follow the installation instructions.
  • 11. Installing Packages  Install the packages (Optional)  Run R studio.  Click on the Packages tab in the bottom-right section and then click on install. The following dialog box will appear.  In the Install Packages dialog, write the package name you want to install under the Packages field and then click install.
  • 13. Operation Symbols Symbol Meaning + Addition - Subtraction * Multiplication / Division %% Modulo (estimates remainder in a division) ^ Exponential
  • 14. Objects in R  Objects in R obtain values by assignment.  This is achieved by the gets arrow, <-, and not the equal sign, =.  Objects can be of different kinds.
  • 15. Built in Functions  R has many built in functions that compute different statistical procedures.  Functions in R are followed by ( ).  Inside the parenthesis we write the object (vector, matrix, array, dataframe) to which we want to apply the function.
  • 16. Vectors The very basic data types are the R-objects called vectors Vectors are variables with one or more values of the same type. When you want to create vector with more than one element, you should use c() function which means to combine the elements into a vector. # Create a vector. apple <- c('red','green',"yellow") print(apple) # Get the class of the vector print(class(apple)) When we execute the above code, it produces the following result − [1] "red" "green" "yellow" [1] "character"
  • 17. Data Frame  Researchers work mostly with data frames  With previous knowledge you can built data frames in R  Also, import data frames into R.  Data frames are tabular data objects Data Frames are created using the data.frame() function. # Create the data frame. BMI <- data.frame(gender = c("Male", "Male","Female"), height = c(152, 171.5, 165), weight = c(81,93, 78),Age = c(42,38,26)) #print(BMI) When we execute the above code, it produces the following result − gender height weight Age 1 Male 152.0 81 42 2 Male 171.5 93 38 3 Female 165.0 78 26
  • 18. Practice  A<-(“Welcome”) then press control R  x<-c(3,4,5,6)  Y<-c(3,4,5,6)  x+y run the command and get result To check data type a<-4 run data Command is # Class(a) and run R to get result
  • 19. Practical Example- Rainfall Zone  setwd("D:")  rain<-read.csv("rainfall_zonewise.CSV",header=TRUE)  fix(rain)  rain<-read.csv("rainfall_zonewise.CSV",header=TRUE)  dim(rain)  names(rain)  rain1<-rain[,c(1,2,4,384:386)]  fix(rain1)  dim(rain1) #average rainfall for last 65 years  levels(rain1$DISTRICT)  rain.dist<- aggregate(rain1$ANNUAL,by=list(rain1$DISTRICT),FUN=mean)  fix(rain.dist) 19
  • 20.  rain.zone<-aggregate(rain1$ANNUAL,by=list(rain1$ZONE),FUN=mean)  fix(rain.zone)  names(rain1)  levels(rain1$DISTRICT)  bkl<-rain1[rain1$DISTRICT=="BAGALKOTE",]  fix(bkl)  plot(rain1$ANNUAL)  plot(bkl$ANNUAL)  plot(bkl$ANNUAL,type="l")  barplot(bkl$ANNUAL)  plot(bkl$YEAR,bkl$ANNUAL,type="l")  plot(bkl$YEAR,bkl$ANNUAL,type="l",main="rainfall trend in bagalkot",xlab="YEAR",ylab="RAINFALL",col="green",lwd=3)  barplot(bkl$YEAR,bkl$ANNUAL,type="l",main="rainfall trend in bagalkot",xlab="YEAR",ylab="RAINFALL",col="green",lwd=3) 20
  • 21.  blr<-rain1[rain1$DISTRICT=="BENGALURU RURAL",]  fix(blr)  plot(rain1$ANNUAL)  plot(blr$ANNUAL)  plot(blr$ANNUAL,type="l")  barplot(blr$ANNUAL)  plot(blr$YEAR,blr$ANNUAL,type="l")  plot(blr$YEAR,blr$ANNUAL,type="l",main="rainfall trend in bengaluru rural",xlab="YEAR",ylab="RAINFALL",col="green",lwd=3)  barplot(bkl$YEAR,bkl$ANNUAL,type="l",main="rainfall trend in bagalkot",xlab="YEAR",ylab="RAINFALL",col="green",lwd=3)  par(mfrow=c(2,1))  plot(blr$YEAR,blr$ANNUAL,type="l",main="rainfall trend in bengaluru rural",xlab="YEAR",ylab="RAINFALL",col="green",lwd=3)  fit<-lm(ANNUAL ~ YEAR,data=bkl)  summary(fit)  abline(fit)  abline(fit,col="blue",lwd=3)  plot(bkl$YEAR,bkl$ANNUAL,type="l",main="rainfall trend in bagalkot",xlab="YEAR",ylab="RAINFALL",col="green",lwd=3) 21
  • 22. Learning R  Because R is interactive, errors are your friends!  MOST IMPORTANT - the more time we spend using R, the more comfortable we become with it. After doing our first real project in R, we won’t look back.
  • 23. Thank you for your time!!