Chapter 2 Introduction to R
Welcome to the wide world of R and RStudio! In this course you will be introduced - gently - into the world of computer programming. Increasingly, data analytics requires the use of specialized tools for analysis. In this course we will be using R and RStudio to analyze different sources of crime data. Before you get started, we will first become acquainted with the software. In this brief introduction I will be introducing a few important things to you:
Let’s get started!
2.1 What is R and RStudio?
R is, at its core, a statistical programming language. However, it is useful beyond simple statistics. Indeed, because it is a programming language it can be used for many different purposes. R is free and open-source, which means anyone can download and use it free of charge. Because of this, R is widely used in many academic and business circles.
RStudio is an integrated development environment (IDE) designed specifically for R. An IDE is simply a piece of software which makes it easier to work with a programming language. R is the programming language that runs under the hood, while RStudio is the piece of software which we will be working with primarily.
That being said, you should always be working in RStudio and not R. You have to install both, and both programs have an icon, but you only want to load RStudio!
2.3 How to locate and load data
Loading data into R can often seem tricky. The important thing to know is that you just need to know how to point R to
a file on your computer. If you type getwd()
in the console window and hit ‘enter’ you should see a pop up showing
you your username on your computer. In the next lab, you will need to know this in order to find a file on your desktop.
getwd()
## [1] "C:/Users/gioc4/Dropbox/crime_mapping_and_analysis"
This is called your working directory. Essentially, this is the default location R will try and look for files. You can also click on the ‘files’ tab under the plot window to interactively view files on your computer. You’ll see more of this in later labs.
Now that you’re familiar with the basics, you should move to Lab 1, where you will learn about installing packages, loading data, and doing some data analysis.