0 ratings 0% found this document useful (0 votes) 4 views 10 pages R Programming
The document provides an introduction to R programming, detailing its capabilities as a statistical computing language and environment. It outlines how to download and install R on various operating systems, including Windows, Mac, and Linux, and emphasizes the importance of using the R website for resources and documentation. Additionally, it explains the unique command-line interface of R and offers guidance on accessing help and additional libraries.
AI-enhanced title and description
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here .
Available Formats
Download as PDF or read online on Scribd
Go to previous items Go to next items
Save r programming For Later
=
GPCET
G. PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY
Accredited by NAC with ‘A’ Grade of UGC, Approved by AICTE, New Delhi
Permanently Affiliated to JNTUA, Ananthapuramu
(Recognized by UGC under 2(f) and 12(B) & ISO 9001:2008 Certified Institution)
Nandikotkur Road, Venkayapalli, Kurnool ~ 518452
Department of Computer Science and Engineering
Lecture Notes
On
R Programming
For IL YEAR —
jemester [Link] CSE (RIS Regulations)
[Link]
Assistant ProfessorUNIT-I
Chapter 1
Introducing R: What It Is and How to Get It
What you will learn in this chapter:
Discovering what R is How to
get the R program
How to install R on your computer How to
start running the R program
How to use the help system and find help from other sources How to get
additional libraries of commands
R is more than just a program that does statistics. It is a sophisticated computer language
and environment for statistical computing and graphies. R is available from the R-Project for
Statistical Computing website ([Link]), and following is some of its introductory
material:
R is an open-source (GPL) statistical environment modeled after $ and S-Plus. The S
language was developed in the late 1980s at AT&T labs. The R project was started by Robert
Gentleman and Ross Thaka (hence the name, R) of the Statistics Department of the University of
‘Auckland in 1995. It has quickly gained a widespread audience. It is currently maintained by the R
core- development team, a hard-working, international team of volunteer developers. The R
project webpage is the main site for information on R. At this site are directions for obtaining the
software, accompanying packages, and other sources of documentation.
R is a powerful statistical program but it is first and foremost a programming language.
‘Many routines have been written for R by people all over the world and made freely available from
the R project website as “packages.” However, the basic installation (for Linux, Windows or Mac)
contains a powerful set of tools for mostpurposes,
Because R is a computer language, it functions slightly differently from most of the
programs that users are familiar with. You have to type in commands, which are evaluated by the
program and then executed. This sounds a bit daunting to many users, but the R language is easy
to pick up and a lot of help is available. It is possible to copy and paste in commands from other
applications (for example: word processors, spreadsheets, or web browsers) and this facility is
very useful, especially if you keep notes as you learn. Additionally, the Windows and Macintosh
versions of R have a graphical user interface (GUI) that can help with some of the basictasks.
R can deal with a huge variety of mathematical and statistical tasks, and many users find that
the basic installation of the program does everything they need. However, many
WARNING
Beware when copying and pasting commands into R from other applications; R can't
handle certain auto formatting characters such as en-dashes or smart quotes.
specialized routines have been written by other users and these libraries of additional tools are
available from the R website. If you need to undertake a particular type of analysis, there is a
very good chance that someone before you also wanted to do that very thing and has written a
3package that you can download to allow you to do it,
R is open source, which means that it is continually being reviewed and improved. R runs on
most computers—installations are available for Windows, Macintosh, and Linux. It also has
good interoperability, so if you work on one computer and switch to another you can take your
work with you.
R handles complex statistical approaches as easily as more simple ones. Therefore once
you know the basics of the R language, you can tackle complex analyses as easily as simple
ones (as usual it is the interpretation of results that can be the really hard bit).
Getting the Hang of R:
Ris unlike most current computer programs in that you must type commands into the
console window to carry out most tasks you require. Throughout the text, the use of these
commands is illustrated, which is indeed the point of the book. Where a command is illustrated in
its basic form, you will see a fixed width font to mimic the R display like so:
[Link]()
‘When the use of a particular command is illustrated, you will see the user- typed input
illustrated by beginning the lines with the > character, which mimics the cursor line in the R
console window like so:
> datal = (3, 5, 7, 5, 3, 2, 6, 8 5, 6, 9)
Lines of text resulting from your actions are shown without the cursor character, once again
mimicking the output that you would see from R itself:
> datal
[1]35753268569
So, in the preceding example the first line was typed by the user and resulted in the output
shown in the second line. Keep these conventions in mind as you are reading this chapter and
they will come into play as soon as you have R installed and are ready to begin usingit!
The R Websit«
The R website at [Link] is a good place to visit to obtain the R program. Itis also a
good place to look for help items and general documentation as well as additional libraries of
routines. If you use Windows or a Mac, you will need to visit the site to download the R
program and install it. You can also find installation files form any Linux versions on the R
website.
The R website is split into several parts; links to each section are on the main page of the site.
The two most useful for beginners are the Documentation and Downloadsections.
Figure 1-1In the Documentation section (see Figure 1-1) a Manuals link takes you to many documents
contributed to the site by various users. Most of these are in HTML and PDF format. You can
access these and a variety of help guides under Manuals => Contributed Documentation. These
are especially useful for helping the new user to get started. Additionally, a large FAQ section
takes you to a list that can help you find answers to many question you might have. There is also
a Wiki, and although this is still a work in progress, it is a good place to look for information on
installing R on Linux systems.
In the Downloads section you will find the links from which you can download R. The
following section goes into more detail on how to do this.
Downloading and Installing R fromCRAN:
The Comprehensive R Archive Network (CRAN) is a network of websites that host the R
program and that mirror the original R website. The benefit of having this network of websites is
improved download speeds. For all intents and purposes, CRAN is the R website and holds
downloads (including old versions of software) and documentation (e.g. manuals, FAQs).
When you perform searches for R-related topics on the internet, adding CRAN (or R) to your
search terms increases your results. To get started downloading R, you'll want to perform the
following steps:
1, Visit the main R webpage ([Link]); you see a Getting Started box with a
link to download R (see Figure 1-2). Click that link and you are directed to select a
local CRAN mirror site from which to download R.
Figure
[ectting Started:
«+ Risa free software environment for statistical computing and graphics. It compiles and runs on a wide
variety of UNIX platforms, Windows and MacOS. To download R, please choose your preferred CRAN
mimor.
‘* Ifyou have questions about R like how to download and install the software, or what the license terms are,
please read our ansivers to frequently asked questions before you send an email.
2. The starting page of the CRAN website appears once you have selected your preferred
mirror site. This page has a Software section on the left with several links. Choose the R
Binaries link to install R on your computer (see Figure 1-3). You can also click the link to
Packages, which contains libraries of additional routines. However, you can install these
from within R so you can just ignore the Packages link for now. The Other link goes to a
page that lists software available on CRAN other than the R base distribution and regular
contributed extension packages. This link is also unnecessary for right now and can be
ignored as well
[Software |
IR Sources
le Binari
[Packages
(Other3. Once you click the R Binaries link you move to a simple directory containing folders for
a variety of operating system (sce Figure 1-4). Select the appropriate operating system on
which you will be downloading R and follow the link to a page containing more information
and the installation files that yourequire.
igure 1-4
Index of /R/bin
iti 3 ;,
® parent director -
(3 ainuxs 23-Jan-2008 18:47 -
macos/ 19-Apr-2005 08:45 -
macosx, 19-Oct-2010 03:27 =
solaris/ 25-Jun-2008 11:30 -
le) windows / 08-Dec-2010 14:26 -
G2 windowsse/ 02-Apr-2010 17:44 =
achel2.2.0 (Linux!SUSE) Server at [Link] Port 80
‘The details for individual operating systems vary, so the following sections are split into
instructions for each of Windows, Macintosh, and Linux.
Installing R on Your Windows Computer:
The install files for Windows come bundled in an .exe file, which you can download from
the windows folder (refer to Figure 1-4). Downloading the .exe file is straightforward (see Figure
1-5), and you can install R simply by double- clicking the file once it is on yourcomputer.
Figure 1-5
R-2.12.0 for Windows (32/64 bit)
Download R 2.12.0 for Windows (37 megabytes, 32/64 bit)
lati r instruct
New features in this version: Windows specific, all platforms.
Run the installer with all the default settings and when it is done you will have R installed.
Versions of Windows post XP require some of additional steps to make R work properly,
For Vista or later you need to alter the properties of the R program so that it runs with
6Administrator privileges. To do so, follow these steps:
1. Click the Windows button (this used to be labeled Start).
2. SelectPrograms.
3. Choose the R folder.
4, Right-click the R program icon to see an options menu (seeFigure!-6).
Figure
, Windows Anytime Upgrade
(i Windows DVD Make
[2 Windows FaxandS¢ Open
© Windows Media Cer Run as administrator
Troubleshoot compatibility
) Windows Update
2D winzip
“A XPS Viewer
U) Accessories Part ey Lest bar
Administrative Took Pin to Start Menu
Games
Open file location
WinZip
Restore previous versions
Maintenance *
Microsoft Office Send to
Microsoft Visual Stu
Moailla Firefox
‘[Link] 31. Copy
PC Tools AntiVirus
Picasa 3
R
Cut
Delete
Rename
e
rm
a
a
a
rm
a
a
ry
as
fe) R240.1 Help Properties
RR rzao.
GB Uninstall R200—=—=~C*~*~* Peach
Back pee ueet cs
5. Select Properties from the menu, You will then see a new optionswindow.
6. Under the Compatibility tab, tick the box in the Privilege Level section (see Figure 1-7)
and clickOK.Figure 1.
Frevous Verona
Comeatbity
Samy
General Shots
you have poblens with this progr andi worked corey om
‘nearer verson f Wincows,sslee the compatby mode that
rnutcheo tat eater vowon,
ii
Conpatbity rods
[Ey] Run this program in compatbiny mode for:
Window XP Genice Pack
setirgs
[irun n 286 ccloe
[PF] Run n 840 489 seven escision
[EDiable vaul hemes
Disable deastop compostin
[F7Diabie dept coating on high OF! eatinge
Frulege Level
[2] Run this program a8 an adit
Sa Ges) Ce
Biches oe
7, Run R by clicking the Programs menu, shortcut, or quick-launeh icon like any other
program, If the User Account Control window appears (see Figure 1-8), select Yesand R runs
asnormal.
Figure 1are
Program name: Rguiise
Publisher Unlenown |
Filecrgin: Hate eve on tis computer
(Y) Show details
(Change when these notificetions appear
Now R is set to run with administrator access and will function correctly. This is
important, as you see later. R will save your data items and a history of the commands you
used to the disk and it cannot do this without the appropriate accesslevel,
Installing R on Your Macintosh Computer
The install files for OS X come bundled in a DMG file, which you can download from the
macosx folder(refer to Figure1-4),
Figure
Rimpkg
U Double-click to install
Once the file has downloaded it may open as a disk image or not (depending how your system
is set up). Once the DMG file opens you can double-click the installer file and installation will
proceed (see Figure 1-9). Installation is fairly simple and no special options are required. Once
installed, you can run R from Applications and place it in the dock like any otherprogram.
Installing R on Your Linux Computer
Ifyou are using a Linux OS, R runs through the Terminal program, Downloadable install files
are available for many Linux systems on the R- website (see Figure 1-10). The website also
contains instructions for installation on several versions of Linux. Many Linux systems also
9=
GPCET
support a direct installation via the Terminal.
Name Last modified Size Description
}® varent directory -
debian/ 18-Oct-2010 17:16 -
© redhat/ 25-Nov-2009 17:01 -
suse/ 18-Dec-2009 10:11 =
G9 ubuntus 11-Oct-2010 06:06 =~
achel2.2.0 (Linux!SUSE) Server at [Link] Port 80
The major Linux systems allow you to install the R program directly from the Terminal, and R
files are kept as part of their software repositories. These repositories are not always very upsto-
date however, so if you want to install the very latest version of R, look on the CRAN website
for instructions and an appropriate install file. The exact command to install direct fiom the
Terminal varies slightly from system to system, but you will not go far wrong if you open the
Terminal and type R into it. If R is not installed (the most likely scenario), the Terminal may
well give you the command you need to get it (see Figure 1-11)!
File Edit View Search Terminal Help
nark@nark-Parallels-Virtual-Platform:~$ R
The progran 'R' is currently not installed. You can install it by typing:
sudo apt-get install r-base-core
nark@nark-Parallels-Virtual-Platform:~$ If
In general, a command along the following lines will usually do the trick:
sudo apt-get install r-base-core
In Ubuntu 10.10, for example, this installs everything you need to get started.
In other systems you may need two elements to install, like so:
sudo apt-get install r-base r-base-dev
The basic R program and its components are built from the r-base part. For many purposes this
is enough, but to gain access to additional libraries of routines the r-base-dev part is needed.
10