What is an .fwf file?

Hey everyone, just a general question: what is a .fwf file? I was learning about some different file types that store rectangular data, and I came across an .fwf file. I searched online but I still don't quite understand what it is. Thanks.

One use for the fwf file extension is for fixed width data. That format stores data with the columns defined with a certain number of characters. The different columns do not need to have the same number of characters, but within a column the number of characters is the same. If the content of a row does not have enough characters, it is padded with spaces. Here is an example.

    17.2 -1.3456   345.9
      -2  1234.512345678

Each column has eight characters. In the first row and first column, the value 17.2 requires only 4 characters, so 4 spaces have been placed before it to achieve the required 8 characters. Notice that the last value in the second row requires all eight characters, so there is no white space between it and the preceding value.
The same data stored as comma separated values would look like this

17.2,-1.3456,345.9
-2,1234.5,12345678

Here is an example of reading the fixed width version of the data with read.fwf() from the readr package.

read.fwf("Dummy.fwf",widths = c(8,8,8))
    V1        V2         V3
1 17.2   -1.3456      345.9
2 -2.0 1234.5000 12345678.0

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.