Search code examples
rvisual-studiomicrosoft-r

making a single xdf files from 2 other xdf files


I am using the RevoScaleR package in MS Visual Studio, and I'm stuck on a step.

I have one XDF file with a column called "Total_Admits_Pred". I have another XDF file with a column called "Total_Admits".

Both XDF files have the same number of rows. I would like to combine the two XDF files into a single XDF file with both of these columns. How could I do that?

Thanks!

Thomas


Solution

  • You would do something like this:

    xdf_df1 <- rxImport("<path/to/xdf1>")
    xdf_df2 <- rxImport("<path/to/xdf2>")
    
    xdfOut <- RxXdfData("<path/to/merged/xdf>") # Should not already exist
    
    # This assumes that xdf2 was the one containing "Total_Admits_Pred"
    # and that xdf1 contained "Total_Admits", you'll have to adjust this
    # based on your data.
    xdf_df1[["Total_Admits_Pred"]] <- xdf_df2$Total_Admits_Pred 
    
    # Verify the Data Frame is correct
    head(xdf_df1)
    
    # Export it
    rxDataStep(inData = xdf_df1, outFile = xdfOut)