My problem is that I need to compare multiple columns containing Dates, to a reference column (ref_date here) and store the number of observations which are before/smaller than that reference date for each row, in a new column (let's call it count_date).
I hereby provide a little sample data:
ID <- c("1", "2", "3", "4", "5")
date1 <- sample(seq(as.Date('2000/01/01'), Sys.Date(), by="day"), 5)
date2 <- sample(seq(as.Date('2000/01/01'), Sys.Date(), by="day"), 5)
date3 <- sample(seq(as.Date('2000/01/01'), Sys.Date(), by="day"), 5)
ref_date <- sample(seq(as.Date('2000/01/01'), Sys.Date(), by="day"), 5)
count_date <-0
df_test <- data.frame(ID,date1,date2,date3,ref_date,count_date)