What is R?
R is an open-source programming language used mainly for statistical analysis. It is a GNU project similar to the S language. Its built-in packages allow for advanced statistical functions and simple graphic creation. With additional plugins, these abilities can become even more powerful and customizable.
What are R's strengths?
R's strength include:
- its varying data structures, which can be more intuitive than data storage in other language
- its built-in statistical and graphical functions
- its large collection of useful plugins that can enhance the language in many different ways
- it has a common API for interacting with most file structures to access data stored outside of R
Can we run R as a series of console commands?
Yes. R can be run either as a series of console commands, or as full scripts.
How can we install R?
R can be run on many operating systems like Linux, OS X, and Windows. Visit https://cran.rstudio.com for download links and instructions. We will need a Fortran compiler in order to be able to run R. For extensive details on installation for your particular system, go to https://cran.r-project.org/doc/manuals/r-release/R-admin.html
What is RStudio?
RStudio is a popular open-source integrated development environment (IDE) for R. It includes a console for directly executing R commands, as well as an editor for building longer R scripts. It is also able to keep track of and view variable data and access documentation and R graphics in the same environment. RStudio also allows us to enable additional R packages through the interface without a command. We can download RStudio from https://www.rstudio.com/products/rstudio/download.
How can we launch the R shell / console?
Depending on how we install R, it may be:
/usr/local/bin/R
How can we quit the R shell / console?
quit()
How can we run an R script from the command line?
/usr/local/bin/Rscript fileName.r
How can we install an R package using the R shell / console?
install.packages("<package_name>")
What are popular R packages?
- swirl A package for R that gives walkthrough tutorials in the R console. It’s a great hands-on way to get to know R.
- ggplot2 Brings to R more graphical capabilities, allowing for the creation of more complex and more configurable graphs.
- RColorBrewer Contains built-in color palettes for better looking and easier to read graphics.
- data.table Enhances the abilities of data frames and allows for faster processing on large data sets.
- plyr Simplifies the process of performing split-apply-combine operations.
What are the mathematical operators available in R?
- + : addition
- - : subtraction
- * : multiplication
- / : division
- ^ : exponent
- %% : modulus (remainder of a division)
- () : Used as normal to force precedence in mathematical expression
How can we define variables in R?
x <- 15
Variables in R are defined using the <- operator. Consider the <- as an arrow pointing from the value of the variable on the right to the variable name on the left. So the expression x <- 15 would store the value 15 into the variable x. When we define a variable in R, it does not automatically print the variable or its value; that is, the interface does not return anything, and will simply ready itself for the next command. To view the content of a variable in R, use the variable name with no additional expressions or functions and execute the command.
How can we learn more about a function in R?
To learn more about a function in R, we can use the ? operator or the help() function. This will give us more information, including a description, usage, and arguments. To learn more about c(), we can enter ?c or help(c). For more information on help(), enter ?help or help(help).
What are logical operators in R?
- < Less than operator.
- <= Less than or equal to operator.
- > Greater than operator.
- >= Greater than or equal to operator.
- == Exactly equals operator.
- != Not equal to operator.
- | OR operator.
- || OR operator that evaluates the leftmost element of a vector.
- & AND operator (evaluated before OR operators).
- && AND operator that evaluates the leftmost element of a vector.
- ! NOT operator.