R - Admin

r

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:

  1. its varying data structures, which can be more intuitive than data storage in other language
  2. its built-in statistical and graphical functions
  3. its large collection of useful plugins that can enhance the language in many different ways
  4. 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?

  1. 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.
  2. ggplot2 Brings to R more graphical capabilities, allowing for the creation of more complex and more configurable graphs.
  3. RColorBrewer Contains built-in color palettes for better looking and easier to read graphics.
  4. data.table Enhances the abilities of data frames and allows for faster processing on large data sets.
  5. plyr Simplifies the process of performing split-apply-combine operations.

What are the mathematical operators available in R?

  1. + : addition
  2. - : subtraction
  3. * : multiplication
  4. / : division
  5. ^ : exponent
  6. %% : modulus (remainder of a division)
  7. () : 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?

  1. < Less than operator.
  2. <= Less than or equal to operator.
  3. > Greater than operator.
  4. >= Greater than or equal to operator.
  5. == Exactly equals operator.
  6. != Not equal to operator.
  7. | OR operator.
  8. || OR operator that evaluates the leftmost element of a vector.
  9. & AND operator (evaluated before OR operators).
  10. && AND operator that evaluates the leftmost element of a vector.
  11. ! NOT operator.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License