Learn R Programming

dataRetrieval (version 1.4.0)

getNWISqwData: Raw Data Import for USGS NWIS QW Data

Description

Imports data from NWIS web service. This function gets the data from here: http://nwis.waterdata.usgs.gov/nwis/qwdata A list of parameter codes can be found here: http://nwis.waterdata.usgs.gov/nwis/pmcodes/ A list of statistic codes can be found here: http://nwis.waterdata.usgs.gov/nwis/help/?read_file=stat&format=table

Usage

getNWISqwData(siteNumber, pCodes, startDate, endDate, expanded = FALSE,
  interactive = TRUE)

Arguments

siteNumber

string or vector of of USGS site numbers. This is usually an 8 digit number

pCodes

string or vector of USGS parameter code. This is usually an 5 digit number.

startDate

string starting date for data retrieval in the form YYYY-MM-DD.

endDate

string ending date for data retrieval in the form YYYY-MM-DD.

expanded

logical defaults to FALSE. If TRUE, retrieves additional information. Expanded data includes remark_cd (remark code), result_va (result value), val_qual_tx (result value qualifier code), meth_cd (method code), dqi_cd (data-quality indicator code), rpt_lev_va (reporting level), and rpt_lev_cd (reporting level type).

interactive

logical Option for interactive mode. If true, there is user interaction for error handling and data checks.

Value

data dataframe with agency, site, dateTime, value, and code columns

See Also

getWQPData, getWQPSites, getWQPqwData, constructNWISURL

Examples

Run this code
# NOT RUN {
# These examples require an internet connection to run
siteNumber <- c('04024430','04024000')
startDate <- '2010-01-01'
endDate <- ''
pCodes <- c('34247','30234','32104','34220')
rawNWISqwData <- getNWISqwData(siteNumber,pCodes,startDate,endDate)
rawNWISqwDataExpand <- getNWISqwData(siteNumber,pCodes,startDate,endDate,expanded=TRUE)
# To get data in Sample dataframe format:
dataColumns <- grep("p\\d{5}",names(rawNWISqwData))
remarkColumns <- grep("r\\d{5}",names(rawNWISqwData))
totalColumns <-c(grep("sample_dt",names(rawNWISqwData)), dataColumns, remarkColumns)
totalColumns <- totalColumns[order(totalColumns)]
compressedData <- compressData(rawNWISqwData[,totalColumns])
Sample <- populateSampleColumns(compressedData)
# }

Run the code above in your browser using DataLab