How to do it…

The following are the steps to convert one or multiple CSV files into a single XDF file:

  1. Set the working directory where the CSV file is stored.
  2. Load the RevoScaleR library.
  3. Extract the CSV filenames and store them in an object.
  4. Create an object with the XDF filename.
  5. 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)
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset