read.fwf {base} | R Documentation |
Read a “table” of fixed width formatted data
into a data.frame
.
read.fwf(file, widths, sep = "\t", as.is = FALSE,
skip = 0, row.names, col.names, n = -1, ...)
file |
the name of the file which the data are to be read from. Alternatively, |
widths |
integer vector, giving the widths of the fixed-width fields (of one line). |
sep |
character; the separator used internally; should be a character that does not occur in the file. |
as.is |
see |
skip |
number of initial lines to skip; see
|
row.names |
see |
col.names |
see |
n |
the maximum number of records (lines) to be read, defaulting to no limit. |
... |
further arguments to be passed to
|
Fields that are of zero-width or are wholly beyond the end of the line
in file
are replaced by NA
.
A data.frame
as produced by read.table
which is called internally.
Brian Ripley for R version: original Perl
by Kurt Hornik.
scan
and read.table
.
ff <- tempfile()
cat(file=ff, "123456", "987654", sep="\n")
read.fwf(ff, width=c(1,2,3)) #> 1 23 456 \ 9 87 654
unlink(ff)
cat(file=ff, "123", "987654", sep="\n")
read.fwf(ff, width=c(1,0, 2,3)) #> 1 NA 23 NA \ 9 NA 87 654
unlink(ff)