stroke <- read.csv2("stroke.csv", na.strings=".") names(stroke) <- tolower(names(stroke)) head(stroke) stroke <- within(stroke,{ died <- as.Date(died, format="%d.%m.%Y") dstr <- as.Date(dstr, format="%d.%m.%Y") end <- pmin(died, as.Date("1996-1-1"), na.rm = T) dead <- !is.na(died) & died < as.Date("1996-1-1") obstime <- as.numeric(end - dstr, units="days")/365.25 })