The following are the steps to convert one or multiple CSV files into a single XDF file:
- Set the working directory where the CSV file is stored.
- Load the RevoScaleR library.
- Extract the CSV filenames and store them in an object.
- Create an object with the XDF filename.
- Use the rxImport() function and pass each of the CSV files through it and create an XDF file by appending rows.
Here's the code chunk for the preceding steps:
setwd("D:/AllSync/Drive/Book-3/codeBundle/ch9")
library(RevoScaleR)
csvFiles <- dir(pattern = ".csv")
xdfFile <- file.path(getwd(), "USAirlines2016.xdf")
for(i in 1:length(csvFiles)){
print(csvFiles[i])
if(i!=1){
rxImport(inData = csvFiles[i], outFile = xdfFile,
overwrite = TRUE, append = "rows")
}
else {
rxImport(inData = csvFiles[i], outFile = xdfFile)
}
}