#libraries
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
library(stringr)
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ readr 2.1.4
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(hms)
##
## Attaching package: 'hms'
##
## The following object is masked from 'package:lubridate':
##
## hms
# 1.1 Load the Dawgs Dash dataset and ensure it is good
dawgs_dash <- read_delim("/Users/joonpiter/Downloads/INFO201 HW/data/dawgs-dash-5k-2023.csv")
## Rows: 1734 Columns: 4
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: "\t"
## chr (1): category
## dbl (2): rank, bib
## time (1): time
##
## ℹ 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.
# 1.2 What are the data types of the columns category and time?
head(dawgs_dash)
## # A tibble: 6 × 4
## rank category time bib
## <dbl> <chr> <time> <dbl>
## 1 1 19 | M 16:30 2170
## 2 2 29 | M 16:40 432
## 3 3 23 | M 17:22 2218
## 4 4 23 | M 17:29 1296
## 5 5 20 | M 17:37 959
## 6 6 20 | M 17:58 1646
cat_type <- class(dawgs_dash$category)
time_type <- class(dawgs_dash$time)
cat_type
## [1] "character"
time_type
## [1] "hms" "difftime"
# 1.3 Convert the time to duration, but so that format “mm:ss” is understood as minutes-seconds,
#and “hh:mm:ss” is understood as hours, minutes, seconds.dawgs_dash <- dawgs_dash %>%
dawgs_dash <- dawgs_dash %>%
mutate(
time_seconds = ifelse(substr(time, 3, 3) == ":",
as.numeric(substr(time, 1, 2)) * 60 + as.numeric(substr(time, 4, 5)),
as.numeric(substr(time, 1, 2)) * 3600 + as.numeric(substr(time, 4, 5)) * 60 + as.numeric(substr(time, 7, 8))
)
) %>%
arrange(time)
# Display the modified data frame
print(head(dawgs_dash))
## # A tibble: 6 × 5
## rank category time bib time_seconds
## <dbl> <chr> <time> <dbl> <dbl>
## 1 1457 33 | F 01:00:01 1619 60
## 2 1457 35 | M 01:00:01 1620 60
## 3 1459 40 | F 01:00:05 1217 60
## 4 1460 26 | F 01:00:09 2213 60
## 5 1461 70 | M 01:00:11 130 60
## 6 1462 50 | F 01:00:16 1018 60
#ive tried mutiple ways to get into the MM:SS and HH:MM:SS, and really nothing has worked, this was the closet I could get to something that made sense
# Step 4: Check the time of 3 fastest and 3 slowest runners
fastest_runners <- head(dawgs_dash, 3)
slowest_runners <- tail(dawgs_dash, 3)
# Display results
fastest_runners
## # A tibble: 3 × 5
## rank category time bib time_seconds
## <dbl> <chr> <time> <dbl> <dbl>
## 1 1457 33 | F 01:00:01 1619 60
## 2 1457 35 | M 01:00:01 1620 60
## 3 1459 40 | F 01:00:05 1217 60
slowest_runners
## # A tibble: 3 × 5
## rank category time bib time_seconds
## <dbl> <chr> <time> <dbl> <dbl>
## 1 1453 34 | F 59:52 637 3592
## 2 1455 42 | F 59:53 43 3593
## 3 1456 61 | F 59:59 907 3599
# Step 5: Make a histogram of the running times
hist(dawgs_dash$time_seconds, main = "Dawgs Dash 5k Running Times", xlab = "Time (seconds)", col = "skyblue", border = "black", breaks = 20)

# Load required libraries
library(tidyverse)
# Step 1: Load the dataset and filter columns
data <- read_delim("/Users/joonpiter/Downloads/INFO201 HW/data/UAH-lower-troposphere-wide.csv")
## Rows: 538 Columns: 29
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: "\t"
## dbl (29): year, month, globe, globe_land, globe_ocean, nh, nh_land, nh_ocean...
##
## ℹ 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.
# Select required columns
data <- data %>% select(year, month, globe, nopol, sopol)
# Display the first few lines of the dataset
print(head(data))
## # A tibble: 6 × 5
## year month globe nopol sopol
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1978 12 -0.48 -0.39 -0.45
## 2 1979 1 -0.48 -0.46 -0.16
## 3 1979 2 -0.44 -2.01 -0.8
## 4 1979 3 -0.39 -0.56 -0.53
## 5 1979 4 -0.41 -0.84 -0.26
## 6 1979 5 -0.4 -0.77 0.05
# Step 2: Reshape the dataset into long form
long_form_data <- data %>%
pivot_longer(cols = c(globe, nopol, sopol), names_to = "region", values_to = "temperature")
# Display the reshaped long form dataset
print(long_form_data)
## # A tibble: 1,614 × 4
## year month region temperature
## <dbl> <dbl> <chr> <dbl>
## 1 1978 12 globe -0.48
## 2 1978 12 nopol -0.39
## 3 1978 12 sopol -0.45
## 4 1979 1 globe -0.48
## 5 1979 1 nopol -0.46
## 6 1979 1 sopol -0.16
## 7 1979 2 globe -0.44
## 8 1979 2 nopol -2.01
## 9 1979 2 sopol -0.8
## 10 1979 3 globe -0.39
## # ℹ 1,604 more rows
# Store the long form dataset into a variable
long_form_dataset <- long_form_data
# Step 3: Reshape the long form dataset back into wide form
wide_form_data <- long_form_data %>%
pivot_wider(names_from = region, values_from = temperature)
# Display the reshaped wide form dataset
print(wide_form_data)
## # A tibble: 538 × 5
## year month globe nopol sopol
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1978 12 -0.48 -0.39 -0.45
## 2 1979 1 -0.48 -0.46 -0.16
## 3 1979 2 -0.44 -2.01 -0.8
## 4 1979 3 -0.39 -0.56 -0.53
## 5 1979 4 -0.41 -0.84 -0.26
## 6 1979 5 -0.4 -0.77 0.05
## 7 1979 6 -0.4 -0.76 -0.98
## 8 1979 7 -0.31 -0.2 -0.95
## 9 1979 8 -0.4 -0.26 -1
## 10 1979 9 -0.32 -0.18 -0.11
## # ℹ 528 more rows