An R Introduction to Statistics

R Introduction

fractal-12hWe offer here a couple of introductory tutorials on basic R concepts. It serves as background material for our main tutorial series Elementary Statistics with R.

The only hardware requirement for most of the R tutorials is a PC with the latest free open source R software installed. R has extensive documentation and active online community support. It is the perfect environment to get started in statistical computing.

Installation

R can be downloaded from one of the mirror sites in http://cran.r-project.org/mirrors.html. You should pick your nearest location.

Using External Data

R offers plenty of options for loading external data, including Excel, Minitab and SPSS files. We have included a tutorial titled Data Import on the subject for the purpose.

R Session

After R is started, there is a console awaiting for input. At the prompt (>), you can enter numbers and perform calculations.

> 1 + 2 
[1] 3

Variable Assignment

We assign values to variables with the assignment operator "=". Just typing the variable by itself at the prompt will print out the value. We should note that another form of assignment operator "<-" is also in use.

> x = 1 
> x 
[1] 1

Functions

R functions are invoked by its name, then followed by the parenthesis, and zero or more arguments. The following apply the function c to combine three numeric values into a vector.

> c(1, 2, 3) 
[1] 1 2 3

Comments

All text after the pound sign "#" within the same line is considered a comment.

> 1 + 1      # this is a comment 
[1] 2

Extension Package

Sometimes we need additional functionality beyond those offered by the core R library. In order to install an extension package, you should invoke the install.packages function at the prompt and follow the instruction.

> install.packages()

Getting Help

R provides extensive documentation. For example, entering ?c or help(c) at the prompt gives documentation of the function c in R. Please give it a try.

> help(c)

If you are not sure about the name of the function you are looking for, you can perform a fuzzy search with the apropos function.

> apropos("nova") 
[1] "anova"                "anova.glm" 
   ....

Finally, there is an R specific Internet search engine at http://www.rseek.org for more assistance.