Richard Sprague

R-tude: counting my sleep locations

R programming exercise using tidyverse to analyze and visualize sleep location data tracked over several years in a personal spreadsheet.

An etude is a short musical composition intended for intensive practice on a particular skill. My R-tudes are similar exercises to help me develop my R skills.

This is an R-tude using tidyverse and various summarization functions to help me quickly generate a chart showing where I have slept over the past few years. It’s based on an excel spreadsheet that I read into the variable lifetime, which is a simple dataframe made of two columns: Date and Geo, which tell the geographical location where I slept on a given night.

In tibble form, it looks like this:

Code
lifetime
summary(lifetime)

Here’s how I summarize the number of nights per year, by location

Code
lifetime %>% tidyr::separate(Date,c("Year","Month","Day")) %>%
  dplyr::group_by(Year) %>% dplyr::count(Geo) %>%
  dplyr::filter(n>2) %>% spread(Year, n)

There you go! This one line of R prose gives me another dataframe organized by year, showing only the locations where I slept for at least 2 nights.

Technology

Keep reading

Decentralized Science (DeSci) at SynBioBeta 2025

Accelerating Scientific Development Using Crypto Networks

AI

All about AI and LLMs

How I think about large language models

How I expect to be using AI Large Language Models in the future.

Search