Chapter 1. Instant R Starter

Welcome to Instant R Starter. This book has been created especially to provide you with all the information that you need to set up with R. You will learn the basics of R, get started with manipulation of R objects, write your own functions, and discover some tips and tricks for using R.

This document contains the following sections:

So, what is R? shows you what R actually is, what you can do with it, and why it’s so great.

Installation teaches you how to download and install R with a few easy steps and then set it up so that you can use it as soon as possible.

Quick start – R language will make you familiar with the R language. You will learn how to create different objects (vectors, matrices, data frames) and you will see some practical examples of their manipulation and use.

Top 5 features you need to know about will teach you how to perform five tasks with the most important features of R. By the end of this section you will be able to perform data input and output in the system, use flow control and loops, write your own functions and debug them, and create basic plots.

People and places you should get to know provides you with many useful links to the project’s page and forums, as well as a number of helpful guides, tutorials, blogs, and the Twitter feeds about R, as every open-source project is centered around a community of users.

So, what is R?

R is a high-level language and environment for data analysis and visualization. It provides an environment in which you can perform statistical analysis and produce high-quality graphics. It is actually a complete programming language derived from the statistical programming language S. It has been developed and is maintained by a core of statistical programmers, with the support of a large community of users. It is most widely used for statistical computing and graphics, but is a fully functional programming language well suited for scientific programming, data management, and data visualization in general.

The interaction with the R system is mainly command-driven, with the user typing in text and asking R to execute the specific command. As soon as you start R, a session will be opened on which the commands may be introduced and the expression executed. Complex procedures can be implemented in the scripts, which are executed as soon as they are loaded into the system or, more efficiently, as functions, which can be loaded in the system and used when needed.

Getting help

R can do a lot more than what a typical beginner can be expected to need. R also comes with extensive online help in text form as well as in HTML files. The help pages can be accessed via the Help section in the cascade menu or via the help.start() command on the console. You will notice that all the help pages present the same structure, and if they don't appear to be clear at a first glance, they contain all the main information you will need. Normally, all the functions as well as the datasets contained in the packages have their own specific help file. The easiest way to access such pages is to call the help() function with an argument as the name of the R object for which you desire help; for example, help for the function mean() can be found with the command help(mean). As an alternative, the prefix form ?mean is also available. Within R, there is also an option available that searches for all the functions containing a specific word; for example, with the command apropos("mean"), it is possible to search for all the functions containing the word mean. Remember that all the help pages are available only if the package containing the function is loaded in the workspace.

Additionally, a series of manuals are also available in the Help section of the cascade menu. Of particular interest for a beginner is the manual An introduction to R, which contains an introduction to the R language and environment. For a more advanced usage, the Writing R Extensions manual is extremely useful, which is focused on the creation of R packages.

R packages

An R package is a collection of source code and other additional files that, when installed in R, allow the user to load them in the workspace via a call to the library() function. An example of code to load the package lattice may be found as follows:

> library(lattice)

An R installation contains one or more libraries of packages. Some of these packages are part of the basic installation and are loaded automatically as soon as the session is started. Others can be installed from the CRAN, the official R repository, or downloaded and installed manually. Package files are compiled as a .zip file on Windows, as .pkg for Mac OS, or as a source code package for Linux X. In Windows, the manual installation can be performed by simply downloading the .zip file and loading it on R by following the path Packages | Install Package(s) from local ZIP files in the cascade menu. Anyhow, in general, the installation via the CRAN repository should be preferred, since in this way it will be downloaded automatically. Also the dependency of the package you are installing will be downloaded automatically, which otherwise should be installed manually with the manual installation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset