Sapsi
Sapsi

Reputation: 721

Data Tables in R: manipulating a column with/without a subset filter

Suppose i have a data table

library(data.table)
ff=data.table(date=c("2013-01-01","2013-01-02","2013-01-03","2013-02-02"),x=c(1,2,3,4));  
setkey(ff,date)

Then this works ff[,as.Date(date)] but this doesn't ff['2013-01-01',as.Date(date)] the latter throwing the error

"Error in as.Date.default(date) : do not know how to convert 'date' to class “Date”"

Upvotes: 0

Views: 141

Answers (1)

Ricardo Saporta
Ricardo Saporta

Reputation: 55350

As @Justin pointed out, this is fixed in the next release.
A temp workaround for 1.8.10 is to daisychain the [][] as in:

 ff['2013-01-01'][, as.Date(date)]

 # or, if you want a DT back:
 ff['2013-01-01'][, list(as.Date(date))]

Upvotes: 3

Related Questions