[R] Parsing Files in R (USGS StreamFlow data)

Rolf Turner r.turner at auckland.ac.nz
Mon Oct 5 04:20:27 CEST 2009


On 5/10/2009, at 2:49 PM, stephen sefick wrote:

> http://waterdata.usgs.gov/nwis/uv? 
> format=rdb&period=7&site_no=021973269
>
> I would like to be able to parse this file up:
>
> I can do this
> x <- read.table("http://waterdata.usgs.gov/nwis/uv? 
> format=rdb&period=7&site_no=021973269",
> skip=26)
>
> but If I add another gauge to this
>
> x <- read.table("http://waterdata.usgs.gov/nwis/uv? 
> format=rdb&period=7&site_no=021973269,06018500",
> skip=26)
> It does not work because there are two files appended to each other.
>
> It would be easy enough to write the code so that each individual
> gauge would be read in as a different file, but is there a way to get
> this information in using the commented part of the file to give the
> headers?  This is probably a job for some other programing language
> like perl, but I don't know perl.
>
> any help would be very helpful.

I'm completely clear what's going on here --- (a) I'm not sure what  
you mean by
``using the commented part of the file to give the headers''; the  
headers
are not ``commented'', and (b) I'm puzzled by the fact that there are  
9 column
headers/field names, but only 7 columns/fields.

Be that as it were, here's what I'd do:

x <- read.table("http://waterdata.usgs.gov/nwis/uv? 
format=rdb&period=7&site_no=021973269",
                  skip=23,nrows=1,header=TRUE,check.names=FALSE)
y <- read.table("http://waterdata.usgs.gov/nwis/uv? 
format=rdb&period=7&site_no=021973269",skip=26)
names(y) <- names(x)[1:7]

This ***appears*** to give a reasonably sensible data frame.

Is this anything like what you want?

	cheers,

		Rolf Turner

######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}




More information about the R-help mailing list