[datatable-help] Replace missings by dates in data table
Frank S.
f_j_rod at hotmail.com
Tue Sep 16 19:04:10 CEST 2014
Hi to all members of the list, Let's say I have the following data (small example): DT <- data.table(ID=c(1,1,2), start=c("1985-01-01","1993-07-15","1993-05-17"), end=c("1992-05-01","1997-02-01",NA))I would want to replace missing values by "01-01-2000" in "end" variable, and convert both "start" and "end" columns in as.Date class. I tried the code: DT[ , c("start", "end"):=list(as.Date(start,format="%d/%m/%Y",origin="1900-10-01"),as.Date(ifelse(is.na(end),"01/01/2000",end),format="%d/%m/%Y",origin="1900-10-01")), by=ID] Error in `[.data.table`(DT, , `:=`(c("start", "end"), list(as.Date(start, : Type of RHS ('double') must match LHS ('character'). What I have to change? Am I doing it in a too complicated way? Thanks in advance for any help!!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20140916/447a3a42/attachment.html>
More information about the datatable-help
mailing list