Join tables

Import a dataset with some (fake) genetic information about Penguins:

library(readr)
genetics_tbl <- read_csv("./data/penguin_genetic_diversity.csv")
Rows: 3 Columns: 5── Column specification ────────────────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (2): species, photo
dbl (3): haplotype_div, nucleotide_div, tajima_d
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
genetics_tbl


We can join these columns to the Palmer Penguins dataset:

library(palmerpenguins)
library(dplyr)

Attaching package: ‘dplyr’

The following objects are masked from ‘package:stats’:

    filter, lag

The following objects are masked from ‘package:base’:

    intersect, setdiff, setequal, union
penguins %>%
  left_join(genetics_tbl, by = "species") %>% 
  head()

Reshape Data

We begin by importing the January 2050 projected daily minimum and maximum temperature for Sacramento:

sac_temps_tbl <- read_csv("./data/sacramento_daily_temp_jan2050.csv")
Rows: 248 Columns: 6── Column specification ────────────────────────────────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr  (4): clim_var, period, gcm, scenario
dbl  (1): temp_f
date (1): dt
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
sac_temps_tbl %>% head()


Convert from a long to wide format:

library(tidyr)

sac_temps_tbl %>% 
  pivot_wider(names_from = clim_var, values_from = temp_f) %>% 
  head()


Compute Daily Temperature Rnage

Compute the daily temperature range:

sac_temps_tbl %>% 
  pivot_wider(names_from = clim_var, values_from = temp_f) %>% 
  mutate(diurnal_range_f = tasmax - tasmin) %>% 
  head()
LS0tDQp0aXRsZTogIkV4ZXJjaXNlIDY6IERhdGEgV3JhbmdsaW5nIFB0IDIiDQpvdXRwdXQ6IA0KICBodG1sX25vdGVib29rOg0KICAgIHRvYzogeWVzDQogICAgdG9jX2Zsb2F0OiB5ZXMNCi0tLQ0KDQojIEpvaW4gdGFibGVzDQoNCkltcG9ydCBhIGRhdGFzZXQgd2l0aCBzb21lIChmYWtlKSBnZW5ldGljIGluZm9yb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