Probability with R. Jane M. Horgan
Чтение книги онлайн.
Читать онлайн книгу Probability with R - Jane M. Horgan страница 14
![Probability with R - Jane M. Horgan Probability with R - Jane M. Horgan](/cover_pre848404.jpg)
1.2 Installing R
R is obtained from the website called CRAN (Comprehensive R Archive Network) and is downloaded by proceeding as follows:
Go to the CRAN website at http://cran.r-project.org/;
Choose an operating system from Linux, (Mac) OS X, and Windows appropriate to your computer. In this book, we work in the Windows environment, click “Download R for Windows”;
Choose the “base” package;
Click “Download R 3.6.1”, which is the current version at the time of writing.
Press the option “Run.”
R is now installed, and you should see an “R” icon on your computer. Clicking on this will start up the standard R package.
1.3 R Documentation
R documentation is available at http://cran.r-project.org/manuals, where you will find the following manuals:
An Introduction to R gives an introduction to the language and how to use R for doing statistical analysis and graphics;
The R Language Definition documents the language per se, that is, the objects that it works on, and the details of the expression evaluation process, which are useful to know when programming R functions;
Writing R Extensions covers how to create your own packages, how to write R help files, and the foreign language (C, C++, Fortran, etc.) interfaces;
R Data Import/Export describes the import and export facilities available either in R itself or via packages that are available from CRAN;
R Installation and Administration;
R Internals is a guide to the internal structures of R and coding standards for the core team working on R itself;
The R Reference Index contains all help files of the R standard and recommended packages in printable form.
The documentation may be downloaded or browsed. We suggest that you download and obtain a hard copy of An Introduction to R by Venables et al. (2019) Version 3.6.1 (2019-07-05) and access the others as you require.
1.4 Basics
To familiarize yourself with R, you should work through the commands given below at a workstation to which R has been downloaded.
To start, either click on the R icon (if you have created a short cut on your screen) or go to “Programs,” select R, and then click on the R icon. When the R program is started, and after it prints an introductory message on the screen, the interpreter prompts for input with the command prompt “
Expressions that are typed at the command prompt are evaluated and printed. For example,
6+7*3/2
returns
[1] 16.5
To assign or store data, write
x <- 1:4
Here, the integers 1, 2, 3, 4 are assigned to the vector
x
which returns
[1] 1 2 3 4
To square the elements of
x2 <- x**2
or equivalently
x2 <- x^2
that causes each element in the vector
x2
which gives
[1] 1 4 9 16
To illustrate how R is case sensitive, consider
X <- 10 prod1 <- X*x prod1 [1] 10 20 30 40
Here, the integer 10 is stored in
Some points to note:
<‐ is the assignment operator; in the illustration “ <‐ 1: 4, the integers are assigned to the vector ;
R is case sensitive; for example, and represent different variables;
Variable names can consist of any combination of lower and upper case letters, numerals, periods, and underscores, but cannot begin with a numeral or underscore;
All the above examples of variables are numeric, but we shall see that R supports many other types of data.
The entities that R creates and manipulates are called objects. These include variables, arrays of numbers, strings, or functions.
All objects created in R are stored in what is known as the workspace.
1.5 Getting Help
The easiest way of getting help when you are working in the R environment is to click the Help button on the toolbar.
Alternatively, you can type
help()
for online help, or
help.start()
for an HTML browser interface.