Topic 1 What is R?
According to the official webpage:
- R is a language and environment for statistical computing and graphics. It is a GNU project which is similar to the S language and environment which was developed at Bell Laboratories (formerly AT&T, now Lucent Technologies) by John Chambers and colleagues. R can be considered as a different implementation of S. There are some important differences, but much code written for S runs unaltered under R. http://www.r-project.org/about.html
According to Wikipedia
- R is a free software programming language and a software environment for statistical computing and graphics. The R language is widely used among statisticians and data miners for developing statistical software and data analysis. Polls and surveys of data miners are showing R’s popularity has increased substantially in recent years.
R is the most amazing free statistical software ever!
This recent video by Revolution Analytics does a great job in summarizing R
1.1 Why should we learn R?
R follows a type inference 1 coding structure and provides a wide variety of statistical and graphical techniques, including;
- Linear and non-linear modelling
- Univariate & Multivariate Statistics
- Classical statistical tests
- Time-series analysis/ Econometrics
- Simulation and Modelling
- Datamining-classification, clustering etc.
- For computationally intensive tasks, C, C++, and Fortran code can be linked and called at run time.
- R is easily extensible through functions and extensions, and the R community is noted for its active contributions in terms of packages.
# Number of R Packages length(available.packages(repos = "http://cran.us.r-project.org")[, 1])
- Total 18872 packages and counting
1.2 Installing R and RStudio on Windows
The latest version of R can be download from the R homepage.
R download page: http://www.cran.r-project.org/bin/windows/base/ The page also provides some instructions and FAQ’s on R installation.
RStudio IDE ( IDE: Integrated Development Environment) is a powerful and productive user interface for R.
It’s free and open source, and works great on Windows, Mac, and Linux
1.3 RStudio GUI/IDE
RStudio GUI is composed of 4 panes which can be rearranged according to the requirements.
There are a lot of short introductions to RStudio available online so we will not go into more details.
Download Rstudio from here https://rstudio.com/products/rstudio/download/#download
The figure below gives the snapshot of RStudio GUI.
- A short intro to RStudio
RStudio Overview - 1:30 from RStudio, Inc. on Vimeo.
1.4 Installing Packages
The easiest way to install packages is to do it via R console. The command install.packages(“package name”) installs R packages directly from internet. Other options to install various dependencies to a package can be easily specified when calling this function. A call to this function asks the user to chose a CRAN mirror at the first instance.
Run the following to install Quantreg package on R. Also use the help function to get the details.
# Install a package using RStudio Console install.packages("quantreg", dependencies = c("Depends", "Suggests"))
install.packages(c("zoo", "reshape2", "quantreg", "e1071", "foreign", "psych", "pastecs", "ggplot2", "stargazer", "formatR", "plm", "xts", "tseries", "fArma"), dependencies = TRUE) # to be updated
1.5 Getting Help
As R is constantly evolving and new functions/packages are introduced every day it is good to know sources of help. The most basic help one can get is via the help() function. This function shows the help file for a function which has been created by package managers.
- The following can be used to search for a function etc.
#Replace the 'search string' with the expression you want to search ??search string
All the R packages (with few exceptions) have a user’s manual listing the functions in a package. This can be downloaded in PDF format from the R package download page2.
R also provides some search tools given at http://cran.r-project.org/search.html The R Site search is helpful in searching for topics related to problem in hand.
Other than these various good R related blogs are on the internet which can be really helpful. A combined upto date view of 452 contributed blogs can be found at R-bloggers3.
Over all there quite a big community of R Users and help can be found for most of the topics.
1.6 Task Views in R-Introduction & Installation
Task Views in R provide packages grouped together according to a generalized task they are used for.
Table below gives the name of task views available4.
The following commands install the package ctv and then Finance task view.
# install package task views install.packages("ctv") library("ctv") #R function library() is used to call a package # install Finance task view install.views("Finance")
1.7 R core packages
- R comes with few bundled core packages which provide various data analytics/statistical capabilities to R. The base package in R has basic functions and operators which are required for analytical programming, stats is another example of core R packages.
# List of R core packages row.names(installed.packages(priority = "base"))
 "base" "compiler" "datasets" "graphics" "grDevices" "grid"  "methods" "parallel" "splines" "stats" "stats4" "tcltk"  "tools" "utils"
1.8 Example-1 Hello R!
message("Hello R!") #use to display messages print("Hello R!") #use to display variables/messages
 "Hello R!"
= "Hello R!" #type inference no need to define strings! msg print(msg)
 "Hello R!"
- R packages not just come with demo programs but the help files for the functions in R packages mostly have example codes for the particular function. R function example() is helpful in running the example code for a function. For running example code for in quantreg package type
Type inference refers to the automatic deduction of the type of an expression in a programming language.↩︎
For example reference manual for quantreg package is at http://cran.r-project.org/web/packages/quantreg/quantreg.pdf↩︎
Go to [www.r-bloggers.com]: www.r-bloggers.com↩︎
This list of available task views can be found at http://cran.r-project.org/web/views/↩︎