Skip to Main Content
George Mason University | University Libraries
See Updates and FAQs for the latest library services updates. Subject Librarians are available for online appointments, and Virtual Reference has extended hours.

Software: Learn R

Resources to learn and use the Open Source Statistical software R (R-Project)

Are you having trouble with R? 

Most of the issues that new users run into are due to not understanding the basic concepts and terminology, which may not be explicitly taught. You need to know about functions and objects before you can understand R.

All the Basics (Written)

Functions

Functions are like Verbs, they tell the computer what to do.
Functions are the same as those in any programing language, in Algebra, or in Excel.
Look for a word or letter followed by parentheses: word(). The "word" is the name of the function.

⏵ WATCH videos: Functions (~1min) and Arguments (~2min, RStudio) or Using Functions (~4min, Intro 2R)

⏵ READ: Call a function on a number or Run a Function (Posit Recipies) or Functions (R4Epis)

Packages are the code for groups of functions. You must download them to your computer and load them into R to use them.

  • Packages can be specified with :: , as in:    package::function()
  • In help documentation, they are designated with braces {} as in:   {package}

⏵ WATCH videos: Installing Packages (~2min, RStudio) or Installing R Packages (~4min, Intro 2R)

The Pipe |>  (or the older tidyverse %>%) is a way to "chain" functions to avoid nesting parentheses and improve workflow.

⏵ WATCH Video: Pipe |> (~5min) (LinkedIn Learning - Mason Log in)


Objects

Objects are like nouns, they label something.
An Object is a name (word) that represents something, whether a single value, a group of values, an entire dataset, or even R code (e.g., function). Some programmers call these "variables", but R's term is "objects" to avoid confusion with data variables (columns in tabular data).

Objects are created with  <- (the "assignment operator") as in  object <- contents

⏵ WATCH Videos: Objects in R (~3min, Intro 2R)

⏵ READ: Objects (R4Eips) - Includes the topics below.

Objects have structures and types which are properties based on the contents.
Functions may do different things based on these qualities.

Structures include: vector, list, data.frame, and matrix
Types / Classes include: chrnumdbl, int, logi,  and fct

⏵ WATCH Videos: Data Types and Structures (~10 min, LinkedIn Learning - Mason Log in) or Data Formats ~15 min, DataLab CC

Parts of objects are referred to using $ , [] or [[]]

In many cases, object is a data frame, and part is a variable within (both referred to by their names). 
But, an R list object can contain any data type, including other lists or data frames.

object["part"]   →  an object containing only the part

object[["part"]] →  the part

object$par       →  the part, common shorthand