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.
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.
::
, as in: package::function(){}
as in: {package}The Pipe |>
(or the older tidyverse %>%
) is a way to "chain" functions to avoid nesting parentheses and improve workflow.
|>
(~5min, LinkedIn Learning - Mason LIL Log in)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: chr
, num
, dbl
, 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
Ask a Librarian | Hours & Directions | Mason Libraries Home
Copyright © George Mason University