R For Dummies - Sample
R For Dummies - Sample
R For Dummies - Sample
Making Everythin
R
Learn to:
Use R for data analysis and processing Write functions and scripts for repeatable analysis Create high-quality charts and graphics Perform statistical analysis and build models
Chapter 1
ith an estimated worldwide user base of more than 2 million people, the R language has rapidly grown and extended since its origin as an academic demonstration language in the 1990s. Some people would argue and we think theyre right that R is much more than a statistical programming language. Its also: A very powerful tool for all kinds of data processing and manipulation A tool that makes all kinds of publication-quality graphics and data visualizations A collection of freely distributed add-on packages A toolbox with tremendous versatility In this chapter, we fill you in on the benefits of R, as well as its unique features and quirks.
You can download R at www.r-project.org. This website also provides more information on R and links to the online manuals, mailing lists, conferences and publications.
CO
PY
RI
GH
TE
MA
TE
RI
AL
10
11
It runs anywhere
The R Development Core Team has put a lot of effort into making R available for different types of hardware and software. This means that R is available for Windows, Unix systems (such as Linux), and the Mac.
It supports extensions
R itself is a powerful language that performs a wide variety of functions, such as data manipulation, statistical modeling, and graphics. One really big advantage of R, however, is its extensibility. Developers can easily write their own software and distribute it in the form of add-on packages. Because of the relative ease of creating these packages, literally thousands of them exist. In fact, many new (and not-so-new) statistical methods are published with an R package attached.
12
13
Next, well add the value 2 to each element in the vector x and print the result:
> x + 2 [1] 3 4 5 6 7
You can also add one vector to another. To add the values 6:10 elementwise to x, you do the following:
> x + 6:10 [1] 7 9 11 13 15
To do this in most other programming language would require an explicit loop to run through each value of x. This feature of R is extremely powerful because it lets you perform many operations in a single step. In programming languages that arent vectorized, youd have to program a loop to achieve the same result. We introduce the concept of vectors in Chapter 2 and expand on vectors and vectorization in much more depth in Chapter 4.
14