Hands-On Exploratory Data Analysis with R
上QQ阅读APP看书,第一时间看更新

read_fwf method

The read_fwf method is used to read data from fixed width files, where every field is in the same place in every line. The default usage will be to read the data in text format in the R workspace. The code for this is shown as follows:

read_fwf("data.txt")

Here, readr will try to guess the column widths. However, to avoid errors, you could also specify column widths explicitly as follows:

read_fwf(data.txt, fwf_widths(c(10, 20, 18), c("ID", "Revenue", "Region")))