I have a dataset that is stored into a variable called "new" and I am trying to write this to a txt file with fixed specified widths between each column.
I have already tried
library(gdata)
write.fwf(new, file = "test.txt", width = c(57,20,10,6,19,12,10,18), colnames = FALSE, sep = "")
but it seems as though the order that I put the width amounts in don't align with the corresponding columns, such as if I change some to a lower width, it gives "width was too small for column ColumnC" message, even though the width that I specified was for a columnB for example.
I am wanting to be able to set a specified width between each column to have a specific amount of spaces between each of them.
Below is the same txt file format, I just changed all of the names:
SPRN55 TEST ST LOS ANGELES CA 11111 DOE JOHN 1112223333 5555555510.00 N 1111111111
SPRN8658 TEST DRIVE LOS ANGELES CA 11111 DOE JOHN 1112223333 5555555510.00 N 1111111111
SPRN787 TEST DRIVE LOS ANGELES CA 11111 DOE JOHN 1112223333 5555555510.00 N 1111111111
The columns are in the order of ADDR, City, State, ZIP, Last name, first name, phone, account, amount, N, Number
Now when I tried the below code on this sample,
write.fwf(mydata, file = "test1.txt", width = c(57,20,3), colnames = FALSE, sep = "")
I get "'width' (57) was too small for columns: V1 'width' should be at least (237)"
This is similar issue to when I am running this against my real data.