The "[" operator arguments in data.table methods are different than they are for data.frame
–
BondedDustOct 18 '11 at 21:11

1

Please paste the actual error rather than #Produces error. +1 anyway. I don't get any error, which version do you have? There is an issue in this area though, it's been raised before, FR#1224 and FR#1493 are high priority to address. Andrie's answer is the best way, though.
–
Matt DowleOct 19 '11 at 9:43

@Christoph_J Thanks. Are you sure about that invalid times argument error? Work fine for me. Which version do you have?
–
Matt DowleOct 19 '11 at 15:24

I updated my post with the sessionInfo(). However, I checked it on my work machine today. Yesterday, on my home machine (Ubuntu) the same error occurred. I will update R and see if the problem is still there.
–
Christoph_JOct 19 '11 at 16:31

@Christoph_J Please show the grouping command you're struggling with (the real problem). Think you may have missed something simple. Why are you trying to convert column classes?
–
Matt DowleOct 19 '11 at 15:27

1

@Christoph_J If you struggle to manipulate data.tables, why not simply convert them temporarily to data.frames, do the data cleaning and then convert them back to data.tables?
–
AndrieOct 19 '11 at 16:10

1

@Christoph_J If your "real" question is substantially different, then I suggest you post it as a new question. In that way you will get new eyeballs on the question.
–
AndrieOct 19 '11 at 16:55

8

What is the idiomatic way of doing this for a subset of columns (instead of all of them)? I've defined a character vector convcols of columns. dt[,lapply(.SD,as.numeric),.SDcols=convcols] is almost instant while dt[,convcols:=lapply(.SD,as.numeric),.SDcols=convcols] almost freezes up R, so I'm guessing that I'm doing it wrong. Thanks
–
FrankMay 2 '13 at 23:07

1

@Frank See Matt Dowle's comment to Geneorama's answer below (stackoverflow.com/questions/7813578/…); it was helpful and idiomatic enough for me [start quote] Another and easier way is to use set() e.g. for (col in names_factors) set(dt, j=col, value=as.factor(dt[[col]])) [end quote]
–
swihartNov 5 '14 at 18:49

This is a BAD way to do it! I'm only leaving this answer in case it solves other weird problems. These better methods are the probably partly the result of newer data.table versions... so it's worth while to document this hard way. Plus, this is a nice syntax example for evalsubstitute syntax.