1

I've got a problem similar to this one, but in my case the file has also white space as missing value.

I'm working with the meteorological sounding data set from the University of Wyoming, you can find an example here

What I've tried to do so far:

data = read.table("http://weather.uwyo.edu/cgi-bin/sounding?region=samer&TYPE=TEXT:LIST&YEAR=2016&MONTH=02&FROM=1212&TO=1212&STNM=83746",skip=10,nrows=100,fill=T,sep="")

It works fine, apart from the last line that has missing values where R can't place the information in the correct column.Then, I must tell R what to do when it finds multiple white space with white space as missing value together. It looks very tricky for me.

I checked the function read.fwf(), but I'm not sure how it can help me to sort my problem out.

Thank you

Luan

Community
  • 1
  • 1
Fallen lord
  • 196
  • 1
  • 12

1 Answers1

2

The width argument can be used to specify the column width in read.fwf

read.fwf("http://weather.uwyo.edu/cgi-bin/sounding?region=samer&TYPE=TEXT:LIST&YEAR=2016&MONTH=02&FROM=1212&TO=1212&STNM=83746",
width=rep(7, 11), skip=10,n=84)

and n sets the maximum number of rows to read in

ekstroem
  • 5,957
  • 3
  • 22
  • 48
  • It worked very well, thank you. How did you find out the number 7? – Fallen lord Feb 13 '16 at 01:01
  • I looked at the data file you linked to and saw that each column was exactly 7 characters wide.Very low-tech and included a bit of finger counting :) Please accept the answer if it solves/answers your question. – ekstroem Feb 13 '16 at 01:16
  • thanks again! I thought they could have different characters wide – Fallen lord Feb 13 '16 at 02:03
  • They are allowed to have different widths. Then you would just need to specify the individual widths as the width vector: `c(7, 8, 11, 4, 7, 10, 7, 7)` – ekstroem Feb 13 '16 at 02:33