This activity involves the following three key steps:
.icsdata with your partner.
You will inevitably encounter different types of problems during Steps 1 and 2 above. We therefore recommend you iterate through Steps 1 and 2 in their entirety early and often. That way you can identify and address any problems early on. For a full demonstration of Steps 1 and 2, watch this 6m56s YouTube screencast.
Here is the code you’ll need to import your Google Calendar data into R:
# DO THIS: Replace "192.ics" with the name of your calendar file here calendar_data <- "192.ics" %>% # Use ical package to import into R ical_parse_df() %>% # Convert to "tibble" data frame format as_tibble() %>% # Use lubridate package to wrangle dates, times, and timezones. For a list of # timezones run the following command in R: OlsonNames() mutate( start_datetime = with_tz(start, tzone = "America/New_York"), end_datetime = with_tz(end, tzone = "America/New_York"), duration = end_datetime - start_datetime, date = floor_date(start_datetime, unit = "day") ) %>% # Convert calendar entry to all lowercase and rename: mutate(activity = tolower(summary)) %>% # Do data wrangling to compute number of minutes and hours per day group_by(date, activity) %>% summarize(duration = sum(duration) %>% as.numeric()) %>% # DO THIS: After looking at your data, change the time interval length units # if necessary. mutate(hours = duration/60) %>% # OPTIONAL: Filter out rows to only include certain dates: filter("2019-09-01" <= date, date <= "2019-09-06")
Make sure your data looks good by looking at the raw values:
glimpse() from the
dplyr package gives you an alternative look at your data. It also gives you the type of data each column is:
<dttm> being date-time,
<chr> being character (i.e. text), and
<dbl> being double i.e. decimal numerical values.
## Rows: 8 ## Columns: 4 ## Groups: date  ## $ date <dttm> 2019-09-02, 2019-09-02, 2019-09-03, 2019-09-04, 2019-09-04,… ## $ activity <chr> "sleep", "study", "exercise", "sleep", "study", "sleep", "ex… ## $ duration <dbl> 480, 60, 60, 960, 180, 540, 30, 90 ## $ hours <dbl> 8.0, 1.0, 1.0, 16.0, 3.0, 9.0, 0.5, 1.5
Use RStudio’s spreadsheet viewer. Note by setting
eval=FALSE in this code chunk, R Markdown will not “evaluate” this code chunk and ignore it.
Describe the question here.
Describe data visualization #1 (that you’ll create below) here:
Describe data visualization #2 (that you’ll create below) here: