# First Steps in R

## Installing R

The first step is to install R. You can download and install R from the Comprehensive R Archive Network (CRAN).

Mac: - Open the Comprehensive R Archive Network. - Click on “CRAN”. - You’ll see a list of mirror sites, organized by country. - Select a site near you. - Click on “MacOS X”. - Click on the .pkg file for the latest version of R, under “Files:”, to download it. - When the download completes, double-click on the .pkg file and answer the usual questions.

## Installing RStudio

The next step is to install RStudio, a free and open-source integrated development environment (IDE) for R. You can use it for viewing and running R scripts.

• Select the installation file for your system.
• Run the installation file.

## Learn R Basics

First of all, you can take an online course to master the basics of R: Visit the interactive R-Course from DataCamp. With the knowledge gained in this courses, you will be ready to undertake your first very own data analysis.

There are also open and free resources and reference guides for R. Two examples are:

Two key things you need to know about R is that you can get help for a function using help or ?, like this:

?install.packages
help("install.packages")


and the hash character represents comments, so text following these characters is not interpreted:

##This is just a comment


## Installing R Packages

The first R command we will run is install.packages.

An R package is a collection of functions, data, and documentation that extends the capabilities of base R. Many of these functions are stored in CRAN. You can easily install packages from within RStudio if you know the name of the packages.

As an example, we are going to install the package dplyr which we use in our first data analysis examples:

install.packages("dplyr")


We can then load the package into our R sessions using the library function:

library(dplyr)


From now on you will see that we sometimes load packages without installing them. This is because you only need to install a package once, but you need to reload it with the command library every time you start a new R session.

If you try to load a package and get an error, it probably means you need to install it first.

Review the dplyr-documentation to get an overview about the different functionalities of this package.

##### Jan Kirenz
###### Professor

I’m a data scientist educator and consultant.