R Beginner Tutorial – Arrays
R Academy Menu ggplot2 basics: learn ggplot2 in 15 minutes!R Beginner TutorialR Beginner Tutorial – Basic SyntaxR Beginner Tutorial – R ObjectsR Beginner Tutorial –
Home » R Beginner Tutorial
In this beginner R tutorial, we’ll start by setting up RStudio and running some basic code samples. We’ll look at how RStudio looks and feels, how to run and save the code, how to install packages, and more.
Buckle in!
R is a programming language and software environment for statistical computing and graphics. It is free and open-source. It first appeared in 1993 and has gone through a number of releases. Consequently, today R is widely used for data analysis among statisticians and data scientists.
Further, R is a language designed specifically for data analysis and plotting. This differentiates R from Python in the sense that you may find algorithms and functions in R that are not yet covered in Python.
In 1991 Ross Ihaka and Robert Gentleman of the University of Auckland, New Zealand, began an alternative implementation of the S language. They named it partly after their first names and partly as a play on the name of S. The first official release came in 1995. The Comprehensive R Archive Network (today famously known as CRAN) was announced in 1997 with 12 contributed packages.
R has a command-line interface, but there are multiple third-party graphical user interfaces available:
RStudio is a free environment for R scripting. You can download RStudio at https://www.rstudio.com/.
RStudio workspace consists of 4 panes:
We can use Console for any quick coding. For example, let’s assign strings »Hello« and »world« to variables a and b, and concatenate them using paste() function.
a = "Hello"
b = "world"
paste(a, b)
We usually use the Source window for scripting when we want to save our work to a file.
One way to run the code is by selecting Run the current selection button.
But the faster way is to use the CTRL + Enter shortcut.
We can see all our objects in Environment pane.
The pane lists a table of variable names and their corresponding values. For example, we see variable a is a string of value “Hello”.
To clear a variable we use the rm() command. For instance, let’s clear variable a.
rm(a)
But what if we want to clear all the variables? We use the Clear button.
Similarly, we can also use the following command.
rm(list = ls())
We can save our code to file by selecting File > Save As.
After that we select the location and confirm with OK. Consequently, R file is created. All R scripts end with .R.
There are number of available R packages, helping you code your ideas faster. You can check the list at Comprehensive R Archive Network, or CRAN for short at https://cran.r-project.org/.
Here are some of the most famous ones:
To install a package we use install.packages() function. For example, to install ggplot2 we use the following command.
install.packages("ggplot2")
To import the library we use the library() function. For example, to import the ggplot2 library we use the following command.
library(ggplot2)
To list all R base functions we use the following command.
library(help = "base")
In conclusion, this sums up all the basics you need to know to navigate the stable RStudio waters. Continue to the next chapter and learn about the basic R syntax!
If you’re already running late we recommend you head over to our two R crash courses:
For even more amazing tips check out our awesome ExcelOlympics YouTube channel!