R Fundamentals
September 2, 2026
Posit Cloud (formerly RStudio Cloud) is a web service that delivers a browser-based experience similar to RStudio, the standard IDE for the R language.
For our course, we use Posit Cloud for the R programming component.
a <- 1 in the Script Pane.
R packages are collections of ready-made tools for R.
Many packages are already built into R, and thousands more can be installed from the internet (like downloading apps on your phone).
Why use packages?
Examples:
readr → for reading data files quicklydplyr → for cleaning and transforming dataggplot2 → for making beautiful graphs and chartstidyversetidyverse is a collection of R packages built for data analytics.
tidyverse include:
readr → data readingdplyr → data transformationggplot2 → data visualization
install.packages("packageName")install.packages("packageName") to install new packages.tidyverse, type and run the command above in the R Console.Note
If a pop-up appears: While running the installation code, R may ask whether to create a personal library. If you are unsure, choose No. You may not see this message at all; that is normal.
library(packageName)library(packageName) to load a package into your R session.library(tidyverse) loads all the R packages in the tidyverse, including readr, dplyr, and ggplot2.mpg is a built-in dataset from ggplot2, which is part of the tidyverse.read_csv() function comes from the readr package, which is part of the tidyverse.Note
danl-101-2026-0902.R-) / underscores (_)*.R files), # indicates that the rest of the line is to be ignored.<-)<-)libr in the RScript in RStudio and wait for a second.

A value is one piece of data, such as a number, text, or TRUE/FALSE.
A value’s data type tells R how it can work with that value.
7.5
numeric
"Hello!"
character
TRUE
logical
a
variable name
<-
assigns
7.5
numeric value
a is an object name that refers to a value; in this course, we may also call it a variable.
<- assigns the value on the right to the name on the left.
In R, a value stored under a name is an object.
x <- 2
x.x < -3
x is less than negative 3.< and - separates them into two operators, changing the meaning.Note
Keyboard shortcut for <-:
- Windows: Alt + -
- Mac: Option + -
x: 2yTip
Read x <- 2 as “assign 2 to x” or simply “x gets 2.”
| Class | Example | What it represents |
|---|---|---|
| logical | TRUE |
A yes-or-no value |
| numeric | 7.5 or 2 |
R’s usual number class |
| integer | 2L |
A whole number stored explicitly as an integer |
| character | "Geneseo" |
Text inside quotation marks |
| factor | factor("Green") |
A category with a defined set of levels |
Note
Use class(object_name) to ask R how an object is classified.
" ") or single quotes (' ').Geneseo as an object name and looks for its value.2.Note
Integer shortcut: add L to a whole number; for example, 2L.
TRUE or FALSE—written in capital letters without quotes.== compares two values for equality and returns a logical result.Tip
<- stores a value; == compares two values.
c(...) combines values in order to create a vector.mixed, every value becomes text.score · numeric| studentcharacter | scorenumeric | passedlogical |
|---|---|---|
| Ana | 82 | TRUE |
| Bo | 59 | FALSE |
| Chen | 76 | TRUE |
"4.39"characteras.numeric()conversion4.39numericWarning
Conversion can lose information: as.integer(4.39) returns 4. It truncates the decimal; it does not round.
+ prompt means R is waiting for more input+.+: finish the command, or press Esc to cancel it.+ is a continuation prompt—not the addition operator and not an error message.c(60, 70, 80)inputmean()function70outputroundfunction name3.14159argument: value to rounddigits = 2named argumentpackage::name identifies an object’s sourcepackage::name accesses an exported object—such as a data set or function—without first running library(package).Note
For a name conflict, write package1::FN() or package2::FN() to choose the function you intend.
+, -, *, and / perform familiar arithmetic; ^ means “raise to a power.”Tip
Parentheses make your intended order clear to both R and your reader.
| Function call | Question answered | Result |
|---|---|---|
abs(-3) |
How far is \(-3\) from zero? | 3 |
sqrt(16) |
What number squared equals 16? | 4 |
round(3.14159, 2) |
What is this value to two decimal places? | 3.14 |
log(exp(3)) |
What exponent of \(e\) produces \(e^3\)? | 3 |
log(x) is the natural logarithm, \(\ln(x)\); exp(x) calculates \(e^x\).Note
For now, combine vectors of the same length when calculating element by element.