0

I currently am preparing a cohort data analysis and would like to apply the following restrictions.

Participants enter the cohort on their 45th birthday and stay in the cohort for 5 years after their first hospital visit for CHD. I want participants to be present in the study from their 40th birthday (5 year period before cohort entry). Unsure how to proceed with this in R if i am working with birth dates as a proxy for age.

Hope this question is appropriate to ask here. Any suggestions welcome.

Thanks!

emmarv
  • 1
  • 1
  • 1
    Welcome to SO! Probably the best way to proceed with this site would be to see how far you can get on your own and then post a question about a more specific coding problem, along with small reproducible example data and desired output. Some guidance, if you're interested: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/28481250#28481250 – Frank Aug 09 '19 at 21:38
  • For your specific problem, I think aggregating the data to the participant level (with columns for birth date, date of first hospital visit, min date in the study, max date in the study) and then defining the filtering rules could work. Packages like dplyr and data.table are convenient for writing code for this. – Frank Aug 09 '19 at 21:39

1 Answers1

1

Libraries zoo and lubridate can do the work.

  • zoo::ymd is useful to convert strings of the time "1999-10-22" to a date object.

  • lubridate::setdiff is useful to deal with time differences between dates.

I recommend you to learn how to deal with date objects and explore both libraries with little examples (converting dates, seting time differences, suming days to reference dates, etc). Then logic will do the work.