0% found this document useful (0 votes)
14 views19 pages

3 R and

good

Uploaded by

jainpranav3882
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)
14 views19 pages

3 R and

good

Uploaded by

jainpranav3882
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
You are on page 1/ 19

Introduction to R and Rstudio

(Part 1)
Contents

Installing and configuring RStudio, R Packages,


Introduction to Swirl,
Introduction to R
R is an open source programming language and
software environment for statistical computing and
graphics.

The R language is widely used among statisticians and


data miners for developing statistical software and data
analytics tools

3
History of R

Modelled after S & S-plus, developed at AT&T labs in late


1980s.

R project was started by Robert Gentleman and Ross Ihaka


Department of Statistics, University of Auckland (1995).

Currently maintained by R core development team – an


international team of volunteer developers (since 1997).
R resources

http://www.r-project.org/

http://cran.r-project.org/doc/contrib/Verzani-SimpleR.pdf
Download R and RStudio

Download R :
http://cran.r-project.org/bin/

Download RStudio :
http://www.rstudio.com/ide/download/desktop
Installation
Installing R on windows PC :

Use internet browser to point to : http://mirror.aarnet.edu.au/pub/CRAN


Under the heading Precompiled Binary Distributions, choose the link Windows.
Next heading is R for Windows; choose the link base.
Click on download option(R 4.2.1 for windows).
Save this to the folder C:\R on your PC.
When downloading is complete, close or minimize the Internet browser.
Double click on R 4.2.1-win32.exe in C:\R to install .

Installing R on Linux:
 sudo apt-get install r-base-core
Installation
Installing 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.
Version

Get R version
R.Version()

Get RStudio version


RStudio: Toolbar at top > Help > About RStudio
A test run with R in Windows
Double click the R icon on the Desktop and the R Console will open.
Wait while the program loads. You observe something like this.

• You can type your own program at the prompt line >.
Getting help from R console

◦ help.start()
◦ help(topic)
◦ ?topic
◦ ??topic
Packages
R consists of a core and packages.
Packages contain functions that are not available in the core.
R packages are the collection of R functions, sample data, and compile
codes.
In the R environment, these packages are stored under a directory called
"library."
During installation, R installs a set of packages. We can add packages later
when they are needed for some specific purpose. Only the default
packages will be available when we start the R console.
One of the strengths of R is that the system can easily be extended. The
system allows you to write new functions and package those functions in a
so called `R package' (or `R library').
Packages
◦ When you download R, already a number (around 30) of
packages are downloaded as well.
◦ To use a function in an R package, that package has to be
attached to the system.
◦ When you start R not all of the downloaded packages are
attached, nearly seven packages are attached to the system
by default.
◦ You can use the function search to see a list of packages that
are currently attached to the system, this list is also called the
search path.
> search()
[1] ".GlobalEnv" "package:stats" "package:graphics"
[4] "package:grDevices" "package:datasets" "package:utils"
[7] "package:methods" "Autoloads" "package:base"

13
Packages
◦ The function library() can also be used to list all the available libraries on
your system with a short description. Run the function without any
arguments
> library()
Packages in library 'C:/PROGRA~1/R/R-25~1.0/library':
base The R Base Package
Boot Bootstrap R (S-Plus) Functions (Canty)
class Functions for Classification
cluster Cluster Analysis Extended Rousseeuw et al.
codetools Code Analysis Tools for R
datasets The R Datasets Package
DBI R Database Interface
foreign Read Data Stored by Minitab, S, SAS, SPSS,
Stata, Systat, dBase, ...
graphics The R Graphics Package

14
Packages
 To attach another package to the system you can use the menu or
the library function. Via the menu:
Select the `Packages' menu and select `Load package...', a list of available
packages on your system will be displayed. Select one and click `OK',
the package is now attached to your current R session. Via the library
function:
> library(MASS)

15
Packages
Get library locations containing R
 .libPaths()

Getting the list of all the packages installed


 library()

To get all packages currently loaded in the R environment


 Search()

Install a New Package


 install.packages("Package Name")
e.g. install.packages("XML“)
Packages
Install package manually
 Go to R Packages https://cran.r-project.org/web/packages/available_packages_by_name.html
 Download the required package
 Save the package as a .zip file in a suitable location in the local system.
 Run the following command to install this package in the R environment.

 Syntax:
install.packages(file_name_with_path, repos = NULL, type = "source")

 Example:
# Install the package named "XML"
install.packages("E:/XML_3.98-1.3.zip", repos = NULL, type = "source")
Introduction to swirl
Swirl teaches you R programming and data science interactively, at your
own pace, and right in the R console!

Install swirl
Open RStudio (or just plain R if you don't have RStudio) and type the following
into the console:
install.packages("swirl")
Start swirl using following commands on R console:
library("swirl")
swirl()
Introduction to swirl
>swirl()
| Welcome to swirl!
| Please sign in. If you've been here before, use the same name as you did then. If you are new, call yourself
something unique. What shall I call you? Johnny
| Please choose a course, or type 0 to exit swirl.
1: R Programming
2: Take me to the swirl course repository!

Selection: 1
| Please choose a lesson, or type 0 to return to course menu.
1: Basic Building Blocks 11: vapply and tapply
2: Workspace and Files 12: Looking at Data
3: Sequences of Numbers 13: Simulation
4: Vectors 14: Dates and Times
5: Missing Values 15: Base Graphics
6: Subsetting Vectors
7: Matrices and Data Frames
8: Logic
9: Functions
10: lapply and sapply

You might also like