R is a system for statistical computation and graphics. It provides, among other things, a programming language, high level graphics, interfaces to other languages and debugging facilities.
R is an integrated suite of software facilities for data manipulation, calculation and graphical display. It includes
The term "environment" is intended to characterize it as a fully planned and coherent system, rather than an incremental accretion of very specific and inflexible tools, as is frequently the case with other data analysis software[1].
Current Version: 2.12.1 (December 2010)
The following manuals for R were created on Debian Linux and may differ from the manuals for Mac or Windows on platform-specific pages, but most parts will be identical for all platforms. The correct versions of the manuals for each platform are part of the respective R installations. Here they can be downloaded as PDF files or directly browsed as HTML:
Translations of manuals into other languages than English are available from the contributed documentation section (only a few translations are available).
The latex or texinfo sources of the latest version of these documents are contained in every R source distribution (in the subdirectory <kbd>doc/manual</kbd> of the extracted archive). Older versions of the manual can be found in the respective archives of the R sources. The HTML versions of the manuals are also part of most R installations (accessible using function <code>help.start()</code>).
You can find here a short introduction and some examples.
We start with first script with standard helloWorld's program. The following program presents a simple FOR-loop. n is input variable via keyboard and program is going to write “Hello world” for n times. You can use # for comments:
# usage in R: helloWorld(n)
helloWorld <- function(n)
{
for (i in 1:n){
cat("Hello world!\n")
}
}
You can after initialisation of function “helloWorld”. For example simply type in R-Console
>helloWorld(3)
And the result seems as follows:
Hello world!
Hello world!
Hello world!
In first example, we used keyboard as input, but R can use a file as standard input too. The following command read one csv-file and writes to array “s”:
s <- read.csv(filename)
You can create your first diagram with using commands par and plot. par can be used to set or query graphical parameters. Parameters can be set by specifying them as arguments to par in tag = value form, or by passing them as a list of tagged values.
par(mfrow=c(1,1))
plot is the generic function for plotting of R objects.
plot(dnorm,-5,5,ann=FALSE)
You can use function title, to add text and colour to your plot.
title(main ="Normal (0,1)",col.main="red", xlab="x", ylab="f(x)",col.lab="blue",
cex.main = 1.5,font.main = 3, cex.lab=1.3, font.lab=3)
curve is another helpful function for drawing given function or expressions:
curve(sin, -2*pi, 2*pi, col="green")