R is a programming language and software environment for statistical analysis, graphics representation and reporting. It is a free tool with a large community and leverages the analysis of data via its huge package libraries that support various analysis operations.
RStudio: RStudio is a development environment for R. Its a place that is built to make using R as effective and efficient as possible. It includes a console, syntax-highlighting editor that supports direct code execution, as well as tools for plotting, history, debugging and workspace management.
Step 1: Visit www.rstudio.com and go to Download RStudio.
Step 2: Click on RStudio Desktop.
Step 3: Select Download RStudio Desktop.
Step 4: From there you can download one to install in your system.
Step 5: When you open RStudio after installing it in your computer, it looks like the following.
- It has a Console where you can run any command, a Source editor where you can type in commands and scripts then save it for later.
- An Environment which tells you about the things that you have already created, a History which keeps track of the commands that you have done and enables you to reuse them.
- It has Packages which are bundles of functions that gives you controls to perform various tasks in R, Plots that help you analyze data graphically.
- It also has a Help which is built in, that lets you learn about a function and what it does.
Packages in R: Packages are collections of R functions, data, and compiled code in a well-defined format. The directory where packages are stored is called the library. R comes with a standard set of packages.
Step 1: From the toolbar of RStudio, click on Tools then Install Packages.
Step 2: Now the Install Packages dialog box appears, where you can search for the package you want to install and change the location of where it will be stored.
Step 3: Suppose you want to install the xlsx package, type in xlsx under the Packages area and press Install.
Step 4: In the Console window, you can see the xlsx package being successfully installed.
Step 5: The commands and functions built into the package are only available to you if you load the library of commands for that package.
For instance you can load the library of xlsx package. After loading you can see the required packages are also being checked under Packages. Libraries disappear when ending an R session so you must load the library each R session that you would like to use the package.
Step 6: To check the previously installed Libraries/Packages type the command library().
Step 7: To access the help menu for a particular package, you can type help and specify the package you would like to have help for.
Step 8: To delete or remove a package, type in remove.packages and specify the package that has already been installed.
Step 9: To save the R script, go to File then click on Save All or Save As and select the desired location for it to be saved.
Step 10: To quit an R session, type in q() at the R prompt.