2
votes

Is it possible to specify the data type of numeric columns in fread? Commands like

prices = markets[, fread(paste(mkt, 'price.csv')), by = mkt]

will fail if price data are integers in one file and floats in another.

So instead of a clean one-liner, I have to explicitly write a for-loop and cast the data type to numeric and concatenate the results.

1

1 Answers

4
votes

You can use the colClasses = argument.

fread("mytable.csv", colClasses = c("character", "character", "numeric"))