R is an open source programming language and software environment for statistical computing and graphics. The R language is widely used among statisticians for developing statistical software and data analysis. R was created by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand, and now, R is developed by the R Development Core Team. To download R and install it on your computer, you can get it at the Comprehensive R Archive Network (http://cran.r-project.org). One option that you may want to explore is RStudio (http://rstudio.org) which is a very nice front-end to R and works on all platforms.
The R System is divided into 2 conceptual parts:
R objects can have attributes: names or dimnames, dimensions (e.g. matrices, arrays), class, length, or any other user-defined attributes/metadata. attributes of an object can be access using the attributes() function.
Go to Start > Programs > R > R . This will open the R prompt which we will use to test basic statements. The <- symbol is the assignment operator. When a complete expression is entered at the prompt, it is evaluated and the result of the evaluated expression is returned. The result may/not be auto-printed. The [1] indicates the index of the element in the vector. The # character indicates a comment and anything right to it is ignored.
The : operator can be used to create integer sequence vector.
THe c() function can be used to create vectors of objects.
You could use the vector() function to specify the vector type and length and it will create an empty vector for you.
What about mixing different objects in a vector, implicit casting occurs so that every element in the vector is of the same class (least common dominator).
Objects can be explicitly casted from one class to another using the as.* functions, if available. like :
Nonsensical casting results in NAs
Matrices are vectors with a dimension attribute. The dimension attribute itself is an integer vector of length 2 (nrow, ncol)
Matrices are constructed column-wise, so entries can be thought of starting in the upper left corner and running down the columns.
based on the above fact, matrices can be created directly from vectors by adding a dimension attribute to a vector
Matrices can be created by column-binding cbind() or row-binding rbind(). the example explains it all
Lists are a special type of vector that can contain elements of different classes (notice that its printing is different)
Factors are used to represent categorical data. Factors can be unordered or ordered. Its like an integer vector where each integer has a label, so you create a vector of any type that is treated internally by integers. The following example creates a factor from a vector of strings. When it prints, it prints the values and it has an attribute Levels that represents