Programming

Author
Affiliation

Your Name

University of Kansas Medical Center

Published

July 23, 2026

library(tibble)
library(dplyr)
library(purrr)

sleep_study <- tibble::tibble(
  steps = rnorm(10, 8000, 1500),
  sleep_hours = rnorm(10, 7, 1),
  mood_score = rnorm(10, 50, 10),
  memory_score = rnorm(10, 75, 8)
)

Tier 1: f_to_c()

Formula: C = (F - 32) * 5/9

Write a function called f_to_c() that converts a temperature in Fahrenheit to Celsius. Test it on 98.6 and 32.

f_to_c <- function(temp_f) {
  
}

Tier 2: steps_to_miles()

Formula: miles = steps * 2.5 / 5280 (average stride length of 2.5 ft, 5,280 ft per mile)

Write a function called steps_to_miles() that converts a step count to miles, with a digits argument (defaulting to 1) that controls how many decimal places the result is rounded to. Test it on 8000 steps with the default rounding, and again with digits = 3.

steps_to_miles <- function(steps, digits = ) {
  
}

Tier 3: Apply steps_to_miles() with purrr::map_dbl()

Use purrr::map_dbl() to apply steps_to_miles() to the vector of daily steps below, both on its own and as a new column in a data frame.

daily_steps <- c(4200, 6100, 8000, 9800, 11500)

Stretch goal: forwarding digits through map_dbl()

Any extra arguments added after the function name in map_dbl() get forwarded to that function for every element – the same forwarding idea as ... from Chapter 25.

Repeat the map_dbl() calls above, but this time pass digits = 3 through to steps_to_miles() for every element.