Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
Script to caculate age to the neariest month for Ukbiobank participants
  • Loading branch information
ibishof authored Jan 8, 2024
1 parent f46502a commit b6184a9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ukbiobank/calculate_age.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


# Calculate age when blood was taken
setwd('~/data/ukbiobank')
dates <- read.csv("dates.csv")

# Convert month names to numeric values
dates$month_num <- match(tolower(dates$Month.of.birth), tolower(month.name))

# Convert birth and assay dates to Date objects
dates$birth_date <- as.Date(paste(dates$Month.of.birth, "15", dates$Year.of.birth, sep = " "), format = "%B %d %Y")
dates$Date.of.attending.assessment.centre...Instance.0 <- as.Date(dates$Date.of.attending.assessment.centre...Instance.0, format = "%m/%d/%Y")

# Calculate time difference in years
dates$age_at_blood_draw <- as.numeric(dates$Date.of.attending.assessment.centre...Instance.0 - dates$birth_date) / 365.25


combo <- merge(dates, age, by = "eid")
write.csv(combo, "age_at_blood_drawn.csv")

0 comments on commit b6184a9

Please sign in to comment.