An integrated development environment is software that makes coding easier
Tip
Now, you can just quit and restart RStudio if something goes wrong! You can also go to Session -> Restart R to clear your session.
You can run…
.R
script.qmd
(Quarto) or .Rmd
(R Markdown) file
Make sure your cursor is on the line you want to run -> cmd+return (Mac) or ctrl+enter (Windows)
You can also highlight a section of code and hit cmd+return/ctrl+enter or use the “Run” dropdown in RStudio
.R
files
.qmd
or .Rmd
files
We’ll generally use .qmd
files (Quarto documents) in this course
The most common object we’ll be using R is a dataframe
We’ll talk briefly about some of these
<-
to store objects in the environmentI call this the “assignment arrow”
Now vals
holds those values
Warning
No assignment arrow means that the object will be printed to the console (and lost forever!)
We can retrieve those values by running just the name of the object
We can also perform operations on them using functions like mean()
If we want to keep the result of that operation, we need to use <-
again
We could also create a character vector:
Or a logical vector:
Tip
We’ll see more options as we go along!
We created vectors with the c()
function (c
stands for concatenate)
We could also create a matrix of values with the matrix()
function:
The numbers in square brackets are indices, which we can use to pull out values:
We can pull out rows or columns from matrices:
mean()
, lm()
, table()
, etc.base
, stats
, graphics
, etc.{ggplot2}
, {dplyr}
, {data.table}
, {survival}
, etc. “You only have to buy the book once, but you have to go get it out of the bookshelf every time you want to read it.”
Several days later…
install.packages
, packages are downloaded from CRAN (The Comprehensive R Archive Network)