R: An Introduction

R is a programming language focused on statistics, data visualization, and data analysis. It is open source, which means there is a rich trove of libraries and add-ons constantly being developed by the open source community.

R is free to download and use. Follow the links below to download R if you would like to try it.

  • Windows
  • Linux Binaries
  • RStudio – Not required, but anyone looking for a better developed environment may want to check it out. I will be using just the base install of R for the following lessons though

Starting R

When R first starts up, this is what you will see. I am not going to focus too much on a grand tour, as most of the menus in R are pretty self explanatory. Instead, let’s jump right into the coding. Move your cursor to where my big red arrow is:

rIntro

Basic Syntax

There is an unwritten rule that states the first line of code you need to learn in any language is Hello World. Well, I am not going to do that. R is a stats program. Why don’t we start with some numbers instead.

rIntro1

As you can see, R uses your standard arithmetic operations (+,-,*,/,^)

Variables

Assigning variables in R is easy. “<-” is the designated syntax used to assign a variable. One great thing about R is that you do not need to declare variables in advance. R assigns the data type based on the input you give the variable.

rIntro2

Assigning Strings

rIntro3.jpg

Data Types

The main data types in R are:

  • Numeric: 1, 2.33, etc
  • Integer: 2L
  • Logical: TRUE, FALSE
  • Character: string
  • Complex: 2+3i (remember those from Trig class)

Vectors

Vectors allow you group multiple elements under one name. Use the syntax <-c() when creating a vector

rIntro4

Lists

Lists allow you to group unlike items – even vectors and strings:

rIntro5.jpg

 

 

 

2 thoughts on “R: An Introduction

Please Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s