readNWISstat: Site statistics retrieval from USGS (NWIS)

View source: R/readNWISunit.R

readNWISstatR Documentation

Site statistics retrieval from USGS (NWIS)

Description

Retrieves site statistics from the USGS Statistics Web Service beta. See https://waterservices.usgs.gov/docs/statistics/ for more information.

Usage

readNWISstat(
  siteNumbers,
  parameterCd,
  startDate = "",
  endDate = "",
  convertType = TRUE,
  statReportType = "daily",
  statType = "mean"
)

Arguments

siteNumbers

character USGS site number (or multiple sites). This is usually an 8 digit number.

parameterCd

character USGS parameter code. This is usually a 5 digit number.

startDate

character starting date for data retrieval in the form YYYY, YYYY-MM, or YYYY-MM-DD. Dates cannot be more specific than the statReportType, i.e. startDate for monthly statReportTypes cannot include days, and annual statReportTypes cannot include days or months. Months and days are optional for the daily statReportType. Default is "" which indicates retrieval for the earliest possible record. For daily data, this indicates the start of the period the statistics will be computed over.

endDate

character ending date for data retrieval in the form YYYY, YYYY-MM, or YYYY-MM-DD. Default is "" which indicates retrieval for the latest possible record. For daily data, this indicates the end of the period the statistics will be computed over. The same restrictions as startDate apply.

convertType

logical, defaults to TRUE. If TRUE, the function will convert the data to numerics based on a standard algorithm. Years, months, and days (if appliccable) are also returned as numerics in separate columns. If convertType is false, everything is returned as a character.

statReportType

character time division for statistics: daily, monthly, or annual. Default is daily. Note that daily provides statistics for each calendar day over the specified range of water years, i.e. no more than 366 data points will be returned for each site/parameter. Use readNWISdata or readNWISdv for daily averages. Also note that 'annual' returns statistics for the calendar year. Use readNWISdata for water years. Monthly and yearly provide statistics for each month and year within the range indivually.

statType

character type(s) of statistics to output for daily values. Default is mean, which is the only option for monthly and yearly report types. See the statistics service documentation at https://waterservices.usgs.gov/docs/statistics/ for a full list of codes.

Value

A data frame with the following columns:

Name Type Description
agency_cd character The NWIS code for the agency reporting the data
site_no character The USGS site number
parameter_cd character The USGS parameter code
Other columns will be present depending on statReportType and statType

See Also

constructNWISURL, importRDB1

Examples



x1 <- readNWISstat(
  siteNumbers = c("02319394"),
  parameterCd = c("00060"),
  statReportType = "annual"
)

# all the annual mean discharge data for two sites
x2 <- readNWISstat(
  siteNumbers = c("02319394", "02171500"),
  parameterCd = c("00010", "00060"),
  statReportType = "annual"
)

# Request p25, p75, and mean values for temperature and discharge for the 2000s
# Note that p25 and p75 were not available for temperature, and return NAs
x <- readNWISstat(
  siteNumbers = c("02171500"),
  parameterCd = c("00010", "00060"),
  statReportType = "daily",
  statType = c("mean", "median"),
  startDate = "2000", endDate = "2010"
)



dataRetrieval documentation built on Oct. 31, 2024, 9:07 a.m.