0

I am creating my dataset to carry out a survival analysis. I have these variables: CASE_ID, i_birthdate_c, i_deathdate_c, difftime_c, event1, enddate.

  • Case_id = unique ID
  • birthdate = subject, enters observation
  • deathdate = when they died
  • difftime_c is the time from birth to death
  • event1 = censoring variable indicating death has or has not occurred
  • enddate = when all subjects will be censored if the event has not occurred.

I am trying to calculate the time from i_birthdate_c to enddate (12/31/2013). I want this value to be finally populated in my difftime_c variable if the event1 = 0. As it stands, I have the time from i_birthdate_c to i_deathdate_c for when event1 = 1.

What would be the most efficient way of accomplishing this in R with the existing code I have below? I keep striking out with my if statements.

Model:

newdata$difftime_c <- difftime(newdata$deathdate_c,newdata$birthdate_c,units="weeks")
Werner Hertzog
  • 2,002
  • 3
  • 24
  • 36
CharlieATX
  • 13
  • 1
  • 5
  • You need to provide a snippet of your data as well as a desired output. Take a look at [this](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for a guide. – Abdou Jul 12 '16 at 19:35
  • livebornheart[livebornheart$event1==1, 46] <-livebornheart [livebornheart$event1==1, 39] #conditional formatting for when event==1 livebornheartdata[livebornheartdata$event1==0, 46] <-livebornheartdata[livebornheartdata$event1==0, 44] #conditional formatting for when event==0 – CharlieATX Jul 15 '16 at 18:52
  • Hey Abdou, thanks for responding, but after a bit of trial and error, I got it working. ;) – CharlieATX Jul 15 '16 at 18:52

0 Answers0