0% found this document useful (0 votes)
19 views30 pages

Introduction to R Programming Basics

Uploaded by

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

Introduction to R Programming Basics

Uploaded by

intan suraya
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Introduction to R Programming

Dr. Mohammad Nasir Abdullah


PhD(Statistics), MSc (Medical Statistics), BSc(hons) (Statistics), Diploma in Statistics, Certified Data Science
Specialist, Graduate Statistician (Royal Statistical Society)

Senior Lecturer,
Mathematical Sciences Studies,
College of Computing, Informatic and Media,
Universiti Teknologi MARA,
Perak Branch, Tapah Campus, Perak.
• [Link]
Welcome Pack
• [Link] <- please fill in your email address
• [Link] <- by using email address above, please
register Rstudio Cloud for hands on material.
What is R?
R is a language and environment for statistical
computing and graphics.

R is an open-source implementation of the S


language, which was developed by Bell laboratories.

R is both open source and open development

([Link]

Watch this!
What R Does R Does Not…
• Data handling and storage: • is not a database, but connects to
numeric, textual DBMSs
•matrix algebra • has no graphical user
•Hash tables and regular interfaces, but connects to
Java, TclTk
expressions
• language interpreter can be
• high-level data analytic and very slow, but allows to call
statistical functions own C/C++ code
• classes (“OO”) • no spreadsheet view of data,
• graphics but connects to Excel/MsOffice
• programming language: loops, • no professional / commercial
branching, subroutines support
Advantages using R Disadvantages using R
•Fast and free. •Not user friendly @ start - steep
•R is state of the art: SPSS and SAS learning curve, minimal GUI.
are years behind R! •No commercial support; figuring
• 2nd only to MATLAB for graphics. out correct methods or how to use a
function on your own can be
•Mx, WinBugs, and other programs frustrating.
use or will use R.
•Easy to make mistakes and not
•Active user community know.
•Excellent for simulation, •Working with large datasets is
programming, computer intensive limited by RAM
analyses etc. •Data prep & cleaning can be
•Forces you to think about your messier & more mistake prone in R
analysis. vs. SPSS or SAS
•Interfaces with database •Some users complain about
storage software (SQL) hostility on the R listserve
R is exploding in popularity
Google Trends
“R is the most powerful & flexible statistical
e ol tio nfidential
programming language in the world”1
 Capabilities
 Sophisticated
statistical analyses
 Predictive analytics
 Data visualization
 Applications
 Real-time trading MSFT [2009-

Last 29.29

 Finance 30

 Risk assessment 25

 Forecasting 20

 Bio-technology 15

 Drug development
 Social networks
 .. and more

7
From: The R Ecosystem

R User Community [Link]/R-ecosystem

8
R has a Steep Learning Curve
(steeper for those that knew SAS or other software before)
 Basic commands
 Interface
 Data types
 Packages
 Procedures

12
R History
R is a comprehensive statistical and graphical
programming language and is a dialect of the S
language:
1988 - S2: RA Becker, JM Chambers, A Wilks 1992 - S3: JM
Chambers, TJ Hastie
1998 - S4: JM Chambers
R: initially written by Ross Ihaka and Robert Gentleman
at Dep. of Statistics of U of Auckland, New Zealand
during 1990s.
He retired as an associate professor of statistics at the University of Auckland
Since 1997: international “R-core” team of 15 people
with access to common CVS archive.
15
Installing R
Install the latest Latest version : 4.3.0
version from :
[Link]

Install RStudio:
[Link]

[Link]
[Link]
%2D2023.03.1%[Link]
There are over 15000 add-
R Packages on packages
To date: 19,601 available packages
(31st May 2023)

The most important single innovation in R is the package system, which


provides a cross-platform system for distributing and testing code and data.

The Comprehensive R Archive Network ([Link] distributes


public packages, but packages are also useful for internal distribution.
A particular R
strength:
genetics
• Bioconductor is a suite of
additional functions and some
2,230 packages dedicated to
analysis, visualization, and
management of genetic data
• Much more
functionality than
software released by
Affy or Illumina
The power of Rgraphics
For example : Create beautiful statistical graphics with ggplot2

R has a very powerful graphics system,

With low-level tools allowing customization of every detail


Example of RGraphics
Dashboard
Useful Web links
 Datacamp [Link]
 UCLA Institute for Digital Research and Education
[Link]
 R Reference card:
[Link]
 Undergrad Guide to R :
[Link]
 Quick R: [Link]

57
• The R console “interprets”
whatever you type.
Working • Calculator
with R • Creating variables
• Applying functions.
RStudio
• Easier working with R
• Syntax highlighting, code completion and smart
indentation
• Easily manage multiple working directories and projects.
• More information
• Workspace browser and data viewer
• Plot history, zooming and flexible image and PDF export
• Integrated R help and documentation
• Searchable command history
Latest version 2023.03.1+446  May 2023

• Where code is executed


(where things happen)
• You can type here for
things interactively.
• Code is not saved on
your disk
Rstudio Layout
• If Rstudio doesn’t look like
this (then do:)
• Rstudio -> Preferences ->
Pane Layout
Source/Editor
• Where files open to
• Have R code and
comments in them
• Can highlight and press
(CMD+Enter (Mac)) or
Ctrl+Enter (Windows))
to run the code

• In a .R file (we call a


script), code is saved on
your disk
Workspace/Environment
• Tells you what objects are in
R.
• What exists in memory/
what is loaded?/ what did I
read in?

• History
• Shows previous commands.
Good to look at for
debugging, but don’t rely on
it a scripts. Make a script!
• Also type the “up” key in the
console to scroll through
previous commands.
Other panes
• Files
• Shows the files on your computer of the directory you are working
in
• Viewer
• Can view data or R objects
• Help
• Shows help of R command
• Plots
• Pretty pictures
• Packages
• List of R packages that are loaded in memory
Rstudio Shortcuts
• Ctrl + Enter (CMD + Enter on OSX) in your script evaluates that line of
code
• Ctrl + 1 takes you to the script page
• Ctrl + 2 takes you to the console

• [Link]
Thank you
Email :
nasir916@[Link]

Common questions

Powered by AI

Users familiar with other statistical software like SAS might find R's learning curve steep due to its command-line interface, lack of a comprehensive GUI, and the necessity for understanding programming and statistical theories. Unlike SAS, which often uses more intuitive point-and-click interfaces, R demands more extensive coding knowledge, making initial learning challenging for those not accustomed to programming .

R's powerful graphical capabilities are a significant contributor to its popularity. It allows for the creation of advanced and aesthetically pleasing statistical graphics, particularly with packages such as ggplot2. R's graphics system provides low-level tools for customization, allowing for the adaptation and detailing of visual data representation. This aspect, coupled with its flexibility and ability to integrate with other software, positions R as a leader in data visualization .

R was initially written by Ross Ihaka and Robert Gentleman at the University of Auckland in the 1990s. It evolved from the S language, a statistical computing language. With the establishment of the international R-core team, R developed with contributions from a wide community. This community-driven growth has allowed R to evolve into a robust environment for statistical analysis, supported by extensive package development and integration with other computational tools .

R is particularly strong in applications such as real-time trading, risk assessment, forecasting, biotechnology, drug development, and social network analysis. Its sophisticated statistical analysis capabilities and powerful data visualization tools like ggplot2 make it suitable for industries requiring complex data handling and representation. R's application in bioinformatics and genetics is bolstered by Bioconductor, a suite with over 2,230 packages dedicated to genetic data analysis .

The steep learning curve of R is mainly due to its minimal graphical user interface and the necessity for a deep understanding of programming and statistical concepts right from the start. New users often find the need to figure out correct methods or use functions on their own frustrating. This can be mitigated by leveraging resources such as online communities, structured learning platforms like DataCamp, detailed documentation, and user guides which can provide guidance and shorten the learning process .

R is not a database; while it excels in detailed analysis of data, it relies on importing data from database management systems (DBMSs) for large-scale or persistent data storage. This difference influences R's use in data sciences by combining robust in-memory data manipulation and statistical analysis with the stable, scalable storage capabilities of DBMSs. This synergy allows R to effectively manage and analyze big data in fields like finance and biotechnology .

R packages are crucial as they provide a cross-platform system for distributing and testing code and data, significantly enhancing R's capabilities. With over 19,601 packages available, they allow R to cater to diverse analytical needs, ranging from genetic data analysis with Bioconductor to advanced graphics with ggplot2. Packages enable the expansion of R's functionality beyond what is available in base R, enabling specialized analyses and tasks .

R is considered state of the art and is thought to be ahead of SPSS and SAS. It is fast, free, and excels in graphics, second only to MATLAB. R is particularly powerful for simulation, programming, and complex analyses. Its open-source nature ensures rapid development and a large, active user community for support. Despite its steep learning curve, R forces users to deeply engage with their analyses, potentially leading to better understanding and insights .

R's interoperability allows it to connect with various databases (e.g., SQL) and integrate with programming languages like C/C++. It can also interface with Java through rJava and other GUI libraries like TclTk. This interoperability provides significant advantages, allowing users to leverage R for analytical computing while using other systems for data management or additional computational tasks. It facilitates a versatile analytics environment that can harness external resources for comprehensive analyses .

R handles data through several key features such as the ability to store and manipulate numeric and textual data, matrix algebra, hash tables, and regular expressions. Data manipulation in R can be performed using various high-level statistical functions, object-oriented programming capabilities, and extensive use of packages. Its ability to interface with database management systems allows for efficient data storage and retrieval .

You might also like