Gary Sieling

Summarize Withings Sleep data from R

The following steps list how to export sleep data from Withings, and group/summarize it to identify potential triggers for bad sleep.

The comments in the app are not exportable, but one could use the app to track comma separated tags, re-record later, and run this process.

  1. install r for mac
  2. install rstudio for mac
  3. Export and extract withings data
  4. Copy sleep.csv into a sheet named ‘tags’
  5. Enter comments/tags into the separate sheet

Run the following R code”

install.packages(“tidyverse”)
library(“tidyverse”)

sleep <- read_csv(‘/Users/gsieling/Downloads/data_abc_1234/sleep.csv’)
tags <- read_csv(‘/Users/gsieling/Downloads/tags.csv’)
all <- merge(sleep, tags, all.x=TRUE)

names(all)[names(all) == “Average heart rate”] <- “avg_heart_rate”

all <- all %>%
mutate(trigger = if_else(str_detect(Comments, ‘No alcohol’), ‘No alcohol’, ‘Alcohol’))

all %>%
group_by(trigger) %>%
summarise(avg = mean(avg_heart_rate))

Exit mobile version