Lets say, I loaded a dataset from somewhere and all columns in it are characters, like below
>diamonds2
carat cut color clarity depth table price x y z
<char> <char> <char> <char> <char> <char> <char> <char> <char> <char>
1: 0.23 Ideal E SPECIAL2 61.5 55 326 3.95 3.98 2.43
2: 0.21 Premium E SPECIAL1 59.8 61 326 3.89 3.84 2.31
3: 0.23 Good E VS1 56.9 65 327 4.05 4.07 2.31
But in fact some of them are not characters (could be Date, Time, numeric, integer).
What's the smartest / fastest way to automatically convert all variables in such dataset into their appropriate types (e.g. 'carat' should be numeric, 'table' should be integer and so on, and if there is a variable that looks like "2000-12-31" it will be automatically converted to Date - just like in PowerBI, for example )?
I know the hack - to save data locally as .csv and then open it using fread()
. But how to convert it without saving
My file is quite big, so I need to do it in memory efficiently (i.e. using data.table)