Loading fixed-width dataset into R, losing half of the columns

73 Views Asked by At

I am importing a .txt fixed-width dataset with 16 columns in R, and am losing ~half of the columns upon read.

Hard to create replicable data but some ss/snippets below:

Quick look at data below. The first screeenshot shows what the top half of the data file looks like. The first column are the colnames and second are just dashes (I used the length of those to figure the fixed width by column).

When I look at the .txt file, the all of the column names show, but only the first half of the values within the columns show. Scrolling down halfway through the data, the second half of the column values show. I assumed this was a display issue. However, reading the data in to R, I see the same thing.

MA.sample<- read.fwf(MA_file,
                     widths= c(20, 23,  18, 200,    11, 21, 39, 23, 100, 50,    50, 100,    100,    50, 50, 18),
                     n = 10,
                     skip = 2)

Resulting data only pulls in first half of column values.

[Resulting read data][1]

Any help appreciated! Glad to clarify as needed.

0

There are 0 best solutions below