rfile-iofixed-format

Creating txt file from a dataframe with specific fixed-width format


I have a data frame called dfGL with 22 columns and 17000 rows! The row names are: pressure, diameter, roughness...

I want to create a txt file from this data frame such that:


Solution

  • Here is the solution that works:

    library(gdata)
    
    dfGL <- rbind(colnames(dfGL) , dfGL)
    write.fwf(dfGL, file = "Inpuuuttt.txt", 
              width = 25,rownames = TRUE, colnames = FALSE,  quote = FALSE)