The Big R-Book. Philippe J. S. De Brouwer

Чтение книги онлайн.

Читать онлайн книгу The Big R-Book - Philippe J. S. De Brouwer страница 22

The Big R-Book - Philippe J. S. De Brouwer

Скачать книгу

parameters, then it will only return those.

       Sys.getenv()

      In the example above the function got three variables supplied, hence only report on these three. You will also notice that the variables are wrapped in a special function c(…)xs. This is because the function Sys.getenv() expects one vector as argument and the function c() will create the vector out of a list of supplied arguments.

      Note that in this paragraph above name of the function Sys.getenv() is mono-spaced. That is our convention to use code within text. Even in the index, at the end of this book, we will follow that convention.

      You will also have noticed that in text – such as this line – we refer to code fragments and functions, using fixed width font such as for example “the function mean() calculates the average.” When this part of the code needs emphasizing or is used as a word in the sentence, we might want to highlight it additionally as follows: mean(1 + pi).

      Some other conventions also follow from this small piece of code.We will assume that you are using Linux (unless mentioned otherwise). But do notworry: that is not something that will stand in your way. In Chapter 4 “The Basics of R” on page 21, we will get you started in Windows and all other things will be pretty much the same. Also, while most books are United States centric, we want to be as inclusive as possible and not assume that you live in the United States working from United States data.

       United States of America

       ISO standard

      Learning works best when you can do something with the knowledge that you are acquiring. Therefore, we will usually even show the code of a plot that is mainly there for illustrative purposes, so you can immediately try everything yourself.

      # generate 1000 random numbers between 0 and 100 x <- rnorm(1000, mean = 100, sd = 2) # to illustrate previous, we show the histogram. hist(x, col = "khaki3")# This code follows the ‘hist’ command. # In rare cases the plot will be on the this page # alone and this comment is the previous page.

      In most cases, the plot will be just after the code that it generates – even if the code continues after the plot(…) command. Therefore, the plot will usually sit exactly where the code creates it. However, in some rare cases, this will not be possible (it would create page layout that would not be aesthetically appealing). The plot will then appear near the code chunk (maybe on the next page). To help you to find and identify the plot in such case, we will usually add a numbered caption to the plot.

      The R code is so ubiquitous and integrated in the text that it will appear just where it should be (though charts might move). They are integral part of the text and the comments that appear there might not be repeated in the normal text later.

       $ R R version 3.4.4 (2018-03-15) -- "Someone to Lean On" Copyright (C) 2018 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. [Previously saved workspace restored] >

       $ factor 1492 1492: 2 2 373 $ calc 2*2*373 1492 $ pi 60 3.14159265358979323846264338327950288419716939937510582097494

      Note that in these environments, we do not “comment out” the output. We promise to avoid mixing input and output, but in some cases, the output will just be there. So in general it is only possible to copy line per line the commands to see the output on the screen. Copying the whole block and pasting it in the command prompt leads to error messages, rather than the code being executed. This is unlike the R code, which can be copied as a whole, pasted in the R-command prompt and it should all work fine.

      Questions or tasks look as follows:

      image Question #1 Histogram

Bar chart depicts an example showing the histogram of data generated from the normal distribution.

      Note that the answers to most questions can be found in E “Answers to Selected Questions” on page 1061.The answer might not always be detailed but it should be enough to solve the issue raised.

      Definition: This is a definition

      This is not an book about exact mathematics. This is a pragmatic book with a focus on practical

Скачать книгу