Если вам нужно сначала рассчитать NBD
dat=read.table(text="
ID Alertdate AppointmentDate NBD
1 01/01/2000 04/01/2000 3
1 02/01/2000 04/01/2000 2
2 01/01/2000 04/01/2000 3
2 01/01/2000 05/01/2000 4",h=T)
dat$Alertdate=as.Date(dat$Alertdate,format="%d/%m/%Y")
dat$AppointmentDate=as.Date(dat$AppointmentDate,format="%d/%m/%Y")
dat$NBD=as.numeric(dat$AppointmentDate-dat$Alertdate)
Если таблица не отсортирована
dat=dat[order(dat$ID,dat$Alertdate),]
наконец
do.call(rbind,by(dat,list(dat$ID),function(x){x[1,]}))
ID Alertdate AppointmentDate NBD
1 1 01/01/2000 04/01/2000 3
2 2 01/01/2000 04/01/2000 3