Skip to content
Prev 306410 / 398506 Next

Calculating number of elapsed days from starting date

On 27-09-2012, at 07:16, Marcel Curlin <cemarcel at u.washington.edu> wrote:

            
You could do this

DF$realdate <- as.Date(as.character(DF$date),format="%m/%d/%y")
DF$Days <- ave(as.numeric(DF$realdate), by=DF$Person, FUN=function(x) x-x[1])

If you don't want the as.character then you should add stringsAsFactors=FALSE to the read.table argument list.

Berend