End interactive session 3B
# Create and store the vector ----
<- c("blue", "green", 4, "yellow")
marmots
# Return it ----
marmots
[1] "blue" "green" "4" "yellow"
# Check the class ----
class(marmots)
[1] "character"
Linear algebra basics: scalars, vectors & matrices
A new workflow! GitHub repo FIRST, then R project.
eds212-day3b
EDS-212/
).In your new project:
r-vectors.qmd
Complete the following in your Quarto doc, r-vectors.qmd
:
c()
.
Note that all elements in a vector must be a single class (e.g. all strings or all numeric values) - if strings and numbers are combined, the whole thing will be of class character.
For example:
# Create and store the vector ----
marmots <- c("blue", "green", 4, "yellow")
# Return it ----
marmots
[1] "blue" "green" "4" "yellow"
[1] "character"
If all values are numeric, however, it will be stored as a number:
[1] 12.4 6.8 2.9 8.8 5.0
[1] "numeric"
Notice in the vector above, these are class numeric. If values should be integers (often the case with count data), you can add an L
after the value.
[1] 20 3 5 18 23
[1] "integer"
We learn something important here: even numbers can be stored in R in different ways: floats are numbers that have decimals (these show up as class numeric
) and integers, numbers without decimals (these show up as class integer
).
You’ll learn about data representation and other classes of data in EDS 221.
You can add or subtract numeric vectors of equal length using basic operations. For example, let’s make two new vectors of length 4, then try adding & subtracting them:
Rather than using the Git tab and GUI buttons, let’s perform the same steps using git commands in the Terminal:
git status
to see any newly added or modified files (they should be red) – notice that these match the files in the Git panegit add .
to add (aka stage) all three files at once (analogous to checking the boxes in the Git pane)git status
again to verify that they have been added (they should now be green)
git commit -m "your commit message here"
to commit them (analogous to typing your commit message into the popup window and clicking the Commit button)git status
again to verify that your changes have been committed
git push
(analogous to clicking the Push button)git status
again to verify that your local branch is up to date with ‘origin/main’ (meaning that both your local repo and your remote repo on GitHub now have the same exact commit history)
Whenever you stage / commit / push files using RStudio’s super helpful buttons, RStudio is simply running these git commands in the background.
Why is it worthwhile to get used to running these git commands? As you begin learning new languages and working in different IDEs, you may or may not have GUI buttons for adding / committing / pushing files to GitHub. You can, however, always use the command line to navigate to a git directory, then use these git commands to do so.
End interactive session 3B