Basic+R Course
Basic+R Course
Senior Lecturer,
Mathematical Sciences Studies,
College of Computing, Informatic and Media,
Universiti Teknologi MARA,
Perak Branch, Tapah Campus, Perak.
• https://nasirdrive1.wixsite.com/nasir916
Welcome Pack
• https://tinyurl.com/y2uo4m7x <- please fill in your email address
• https://tinyurl.com/IntroRUCS <- 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.
(http://www.r-project.org/)
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
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 :
http://cran.r-project.org/
Install RStudio:
https://posit.co/
RSTUDIO-2023.03.1-446.EXE
https://posit.co/download/rstudio-desktop/#:~:text=RSTUDIO
%2D2023.03.1%2D446.EXE
There are over 15000 add-
R Packages on packages
To date: 19,601 available packages
(31st May 2023)
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
• 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
• http://www.rstudio.com/ide/docs/using/keyboard_shortcuts
Thank you
Email :
[email protected]