mergeNearest: Merge Datasets

View source: R/mergeNearest.R

mergeNearestR Documentation

Merge Datasets

Description

Merge two datasets based on the the nearest date between each observation.

Usage

mergeNearest(left, dates.left = "DATES", all.left = FALSE,
  suffix.left = "left", right, dates.right = "DATES",
  suffix.right = "right", Date.noon = TRUE, max.diff = "7 days")

Arguments

left

the left-hand dataset.

dates.left

the name of the column of dates in the left-hand dataset.

all.left

logical (TRUE or FALSE), include all rows from the left-hand dataset regardless of whether there is a matching row in the right-hand dataset?

suffix.left

the suffix to apply to common column names in the left-hand dataset.

right

the right-hand dataset.

dates.right

the name of the column of dates in the right-hand dataset.

suffix.right

the suffix to apply to common column names in the right-hand dataset.

Date.noon

logical (TRUE or FALSE), adjust columns of class "Date" to represent a noon observation rather than 12 a.m.?

max.diff

the maximum allowable difference in time for a match. See Details.

Details

The format for max.diff should be a numeric value followed by a description of the time span. The time span must be one of "secs," "mins," "hours," "days," or "weeks" for seconds, minutes, hours, days, or weeks, respectively.

Value

A data frame of the merged data with common column names renamed by the suffix arguments to avoid conflict.

Note

Water-quality data taken at a specific time frequently need to be merged with daily flow data or merged with other water-quality data such as replicate samples or samples of a different medium taken at about the same time, but having a different time stamp.

See Also

mergeQ

Examples


library(smwrData)
data(Q05078470)
data(QW05078470)
# Set the actual time of sampling in QW05078470
QW05078470 <- transform(QW05078470, DATES=DATES + as.timeDay(TIMES))
mergeNearest(QW05078470, right=Q05078470)
# Notice the difference in selected dates
mergeNearest(QW05078470, right=Q05078470, Date.noon=FALSE)

USGS-R/smwrBase documentation built on Oct. 18, 2022, 9:55 a.m.