My dates in the txt file are like, start date= \"011589\" and end date is \"122390\". How can I calculate the duration using R.
I tried mydata$startdate=as.Date(mydata
This can be done using format
Start <- as.Date("011589", "%m%d%y")
Start
#[1] "1989-01-15"
End <- as.Date("122390", "%m%d%y")
End
#[1] "1990-12-23"
If we need the difference in 'days'
as.vector(difftime(End, Start, units='days'))
#[1] 707
Or just use -
to get the difference in 'days'. The above method is more flexible as we can specify the units
as.vector(End-Start)
#[1] 707