Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R - How to Read in a .fwf that contains a # sign

Tags:

r

read.fwf

I am attempting to read in a large fixed width file into R using read.fwf, but I keep getting the error "Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 47 did not have 41 elements". My dataset has 41 columns but when I read in line 48 alone I only get 27 columns. I noticed that the error takes place when it encounters a # sign. How can I either remove the # sign or force read.fwf to ignore it. Here is a little of my code, but since the dataset is massive I am not going to provide it.

df <- read.fwf("flat404.DALLASCOUNTY.20161030.412476", widths = width2, col.names = fields)

Thanks for any help.

like image 973
Braden Avatar asked Dec 03 '25 16:12

Braden


1 Answers

We can set the comment.char argument to blanks or a character that is not a #

df <- read.fwf("flat404.DALLASCOUNTY.20161030.412476", 
         widths = width2, col.names = fields, comment.char = "")
like image 128
akrun Avatar answered Dec 06 '25 06:12

akrun