Data Description

The activities data set has the total daily totals for a Strava user’s cycling activities. The columns are:

  1. date: The YYYY-MM-DD date (will need to be converted to a date type object)
  2. trips: The number of activities recorded for that day
  3. distance: The total distance travelled that day, in kilometers
  4. total_time: The total time elapsed during the activities that day, in seconds
  5. moving_time: The time spent moving that day, in seconds
  6. max_speed: The fastest recorded speed that day, in kph
  7. elevation_gained: the total distance climbed uphill, in meters
  8. dirt_dist: the total distance travelled on gravel or dirt paths, in meters

Question 1: Activities per day for April - October, 2024

Create the data frame seen in Brightspace. Note that kilometers has been changed to miles (1 km = 0.6 mi), meters changed to feed (1 meter = 3.3 feet) and seconds have been changed to hours (1 hour = 3600 seconds). Save the data frame as daily_activities

Note: While not something you should always do, the missing values should be replaced with 0 since NA indicates no activities for that day and no activities -> 0 time, 0 distance, etc…

Hint: You’ll need to use both activities and all_days data frames to form the data set for this question.

## # A tibble: 214 × 8
##    date       trips distance total_time moving_time max_speed elevation_gain
##    <date>     <dbl>    <dbl>      <dbl>       <dbl>     <dbl>          <dbl>
##  1 2024-04-01     0     0         0           0          0               0  
##  2 2024-04-02     0     0         0           0          0               0  
##  3 2024-04-03     0     0         0           0          0               0  
##  4 2024-04-04     0     0         0           0          0               0  
##  5 2024-04-05     0     0         0           0          0               0  
##  6 2024-04-06     0     0         0           0          0               0  
##  7 2024-04-07     1     4.96      0.930       0.528      5.14           95.9
##  8 2024-04-08     0     0         0           0          0               0  
##  9 2024-04-09     1     8.23      0.694       0.668      5.28          107. 
## 10 2024-04-10     0     0         0           0          0               0  
## # ℹ 204 more rows
## # ℹ 1 more variable: dirt_dist <dbl>

Use the code chunk below to check if the data frame is correct by checking that it matches what is in Brightspace.

## # A tibble: 214 × 8
##    date       trips distance total_time moving_time max_speed elevation_gain
##    <date>     <dbl>    <dbl>      <dbl>       <dbl>     <dbl>          <dbl>
##  1 2024-06-24     0     0          0           0         0                0 
##  2 2024-07-21     1     9.54       1.84        1.09      5.18           163.
##  3 2024-04-06     0     0          0           0         0                0 
##  4 2024-09-17     0     0          0           0         0                0 
##  5 2024-07-24     1    12.3        1.01        0.98      6.32           210.
##  6 2024-06-02     1    25.4        2.32        2         5.75           285.
##  7 2024-06-22     0     0          0           0         0                0 
##  8 2024-05-11     1    11.1        1.45        1.16      5.5            159.
##  9 2024-08-10     0     0          0           0         0                0 
## 10 2024-10-15     0     0          0           0         0                0 
## # ℹ 204 more rows
## # ℹ 1 more variable: dirt_dist <dbl>

Question 2: Reformatting the data

Create the data set seen in Brightspace for question 2. Make sure the names of the three columns are the same as in Brightspace, otherwise the next code chunk won’t work.

Note: Before reformatting the data, you’ll need to create a column named average_speed, which is distance/moving_time. Because there are days with no moving time, the fraction will divide by 0 and return NaN. Any days without any activities (trips = 0, distance = 0, and moving_time = 0) should record an average speed of 0.

The attribute column has replaced the _ in the characters ‘moving_time’ and ‘average_speed’ with a space. You can replace characters in a string by using str_replace(column, 'character to replace', 'character doing the replacing')

For example: str_replace('abcde', 'e', 'f') will return ‘abcdf’

## # A tibble: 642 × 3
##    date       attribute     value
##    <date>     <chr>         <dbl>
##  1 2024-04-01 distance          0
##  2 2024-04-01 moving time       0
##  3 2024-04-01 average speed     0
##  4 2024-04-02 distance          0
##  5 2024-04-02 moving time       0
##  6 2024-04-02 average speed     0
##  7 2024-04-03 distance          0
##  8 2024-04-03 moving time       0
##  9 2024-04-03 average speed     0
## 10 2024-04-04 distance          0
## # ℹ 632 more rows