Lesson 2.1: Review loading and previewing data

Lesson 2.1: Review loading and previewing data#

Like we did in Module 1, before we being to analyze our data, we need to do a few steps first.

First, we load in packages to get the tools we need. For this module, we only need the tidyverse package.

# Load packages 
if(!require("tidyverse")) install.packages("tidyverse")
library(tidyverse)
Error in library(tidyverse): there is no package called tidyverse
Traceback:

1. stop(packageNotFoundError(package, lib.loc, sys.call()))

Load in data#

Now it’s time to load in our data! In this scenario, water temperature data and dissolved oxygen data were collected and stored in two separate files. Therefore, we will need to load in both files in order to use them.

As a note, the units for temperature are Celsius (C) and the units for dissolved oxygen are mg/L.

Now that our data is loaded into R, we can explore the data using the view and head commands. Our goal is to make sure things loaded correctly and to get a first look to see if the data make sense.

# if running in google colab, uncomment and use the following lines:
# stream_temp <- read.csv("https://raw.githubusercontent.com/rachtorr/IndigenousEnvDataSci.github.io/refs/heads/main/MOD2/streams_temperature.csv")
# stream_DO <- read.csv("https://raw.githubusercontent.com/rachtorr/IndigenousEnvDataSci.github.io/refs/heads/main/MOD2/streams_DissolvedOxygen.csv")

# read in stream temp data 
stream_temp <- read.csv("streams_temperature.csv", header=TRUE, sep=",")

# read in dissolved oxygen data 
stream_DO <- read.csv("streams_DissolvedOxygen.csv", header=TRUE, sep=",")

View(stream_temp)

head(stream_DO)
A data.frame: 16 × 3
yearStreamAStreamB
<int><dbl><dbl>
200713.2010.20
200812.50 NA
200913.90 NA
201011.3611.67
201112.97 NA
201213.1011.10
201314.4711.42
201413.3711.37
201512.4812.18
201612.6312.03
201713.1611.96
201812.9412.56
201914.1013.00
202012.0712.87
202113.4313.25
202213.2813.78
A data.frame: 6 × 3
yearStreamAStreamB
<int><dbl><dbl>
120077.18 NA
220087.278.07
320097.467.26
420107.00 NA
520116.53 NA
620127.509.50

🧠✍️Class Questions:

  • What do you notice is different between using the command “View” and the command “head”? Which one do you think is more useful?

  • Recalling the previous module, what does the dim() function tell us about a data frame?

dim(stream_temp)
dim(stream_DO)
  1. 16
  2. 3
  1. 16
  2. 3

🧠✍️ Class Questions:

  • How many data entries are in the water temperature data set?

  • How many data entries are in the dissolved oxygen data set?

Lesson 2.1 Recap#

In this lesson we have reviewed:

  • loading a package using library()

  • loading a CSV data file

  • previewing the data frame using View(), head(), and dim()