From the course: R Programming in Data Science: High Variety Data

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Fixed-width files in R

Fixed-width files in R

From the course: R Programming in Data Science: High Variety Data

Start my 1-month free trial

Fixed-width files in R

- [Instructor] Fixed-Width Files or FWF are files where each field is exactly the same width. And I can show you this if you go into the samples file and open up LPO_weather.tdf or tab-delimited. Also open up weather.fwf. If you look at LPO_weather.tdf, and in particular line five and six, you'll see that 280.80 in line five and 80.60 line up on the left-hand side. If you look at the fixed-width version on line five and six, you'll see that 280 and 80.6 don't line up, they line up according to the decimal point and that's because there is a fixed width space making sure that each field is exactly the same width. So, how do you import this data? Well, as you might guess, there are two ways. One is with the base R version and one is with the tidyverse. To do this, the first thing I'm going to do is create a vector called sampleFWF and I'm going to put a file named into that. I'm also going to create fwfFieldPositions and that contains a vector of all of the widths of the fields, and…

Contents