Last active
April 7, 2024 10:20
-
-
Save selfawaresoup/d2b49306fa1f96a33e1d3cac1e7ffe9f to your computer and use it in GitHub Desktop.
Make Apple Health data available for analysis in R as an RDA file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This can take quite a long time to run | |
library(xml2) | |
library(tidyverse) | |
read_xml("apple_health_export/export.xml") -> x | |
x %>% xml_find_all(".//Record") %>% | |
xml_attrs %>% | |
bind_rows %>% | |
mutate( | |
type = factor(type), | |
value = as.double(value), | |
unit = factor(unit), | |
creationDate = as.POSIXct(creationDate), | |
startDate = as.POSIXct(startDate), | |
endDate = as.POSIXct(endDate) | |
) -> health_data | |
save(file="health_data.rda", list=c("health_data")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment