I want to make a long to a wide format and use the factor Levels as binary variables. This means, if the factor Level is existing at least once, then there should be a 1 in the variable. Otherwise a 0. In addition, I want the dates as variable values date.1, date.2,...
What I have is the following
data_sample <- data.frame(
PatID = c(1L, 1L, 1L, 2L, 2L, 3L, 3L, 3L, 3L),
date = c("2016-12-14", "2017-02-04", "NA", "NA", "2012-27-03", "2012-04-21", "2010-02-03", "2011-03-05", "2014-08-25"),
status = c("COPD", "CPOD", "NA", "NA", "Cardio", "CPOD", "Cardio", "Cardio", "Cerebro")
)
What I want is:
PatID COPD Cardio Cerebro date.COPD.1 date.COPD.2 date.Cardio.1 date.Cardio.2 date.Cerebro.1
1 1 0 0 2016-12-14 2017-02-04 NA NA NA
2 0 1 0 NA NA 2012-03-27 NA NA
3 1 1 1 2012-04-21 NA 2010-02-03 2011-03-05 2014-08-25