R
Key concepts that you will learn:
R
?R
?R
and RStudio?We will write code in R
, a statistical programming language, using RStudio. RStudio is an “IDE” or an integrated development environment. Basically, if R
is the engine of our (statistical programming) car, then RStudio is our dashboard, with all of the controls that we’d be more familiar with (plotting window, file visualization pane, help pane, etc.).
Please start by logging into sso.posit.cloud/pomona. Once you’ve logged in, you should see the option to open the Conservation Biology Spring 2023
workspace. You can also access the Conservation Biology Spring 2023
workspace at this link.
At the workspace, you should then see the “Assignment” Week 1
. Please click on that Assignment. Here is a direct link to the Week 1
project, but it may not work if this is the first time ever or in a while that you’re logging into posit.cloud. If it doesn’t work, no worries - just log in through the sso.posit.cloud/pomona link.
RStudio has 3 different panes:
R
interprets
R
to perform an act by giving it commands in the console.R
, view help, and view spreadsheets (Viewer
).R
code!Copy the code below into the console and hit enter. What do you see?
x <- c(1,2,3)
x
You should see the following:
## [1] 1 2 3
Congratulations! You have created your first object in R
: a vector storing the numbers 1, 2, and 3.
You achieved that by using the assignment operator <-
to tell R
to create a new object, x
, that stores the values 1, 2, and 3 in a vector, denoted by c(...)
where the ...
is just a placeholder for whatever you’d like to enter (where each element is separated by commas).
I encourage you to try the following:
myName <- "..."
myName
contains? (Hint: think about what happened when we entered x
in the console earlier.)x
store the values 1, 47, 4747, and 474747?
x <- 1,47,4747,474747
? What does that pesky error message say?