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.

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

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


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

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

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