Learn R Programming

seas (version 0.2-1)

dathomog: Homogenize climate data from two weather stations

Description

Homogenizes daily climate data from two data sets into one data set.

Usage

dathomog(dat1, dat2, dat, by = "date", rm.id = TRUE, plot = FALSE)

# where both dat1 and dat2 are data.frame objects dathomog(dat1, dat2, ...)

# where either dat1 or dat2 is a data.frame, and the other an id dathomog(dat1, dat2, dat, ...)

# both dat1 and dat2 are an id in dat dathomog(dat1, dat2, dat, ...)

Arguments

dat1
data.frame or an id within dat; 1st selection
dat2
data.frame or an id within dat; 2nd selection
dat
data.frame with id column (supply if any of dat1 or dat2 are IDs)
by
name of common column, usually date, which is of class Date
rm.id
logical; strip id column out of resulting data frame
plot
logical; produce cross-plots and correlation statistics of the variables between the two data sets
...
optional args

Value

  • Returns a data.frame of climate data required by most functions in seas. Variable names of the structure are found by a union of the names of dat1 and dat2. The id column is removed if rm.id = TRUE.

synopsis

dathomog(dat1, dat2, dat, by = "date", rm.id = TRUE, plot = FALSE)

Warning

Weather stations should be sufficiently close enough to approximate the same weather. This distance depends on the spatial distance and local climatology.

Details

Data from dat1 has priority over dat2. Where data from dat1 is either NA or missing (outside of range), data from dat2 will be used (if available). Variables will be homogenized where their names are identical, found using names.

The cross-plots of the data are shown only for interest. They show useful correlation statistics, and a best-fit line using perpendicular offsets (which are preferred in this case over traditional linear regression). At some point, the equations for this line may be used to adjust the values from dat2, however this can always be done externally to this function by pre-processing dat2.

References

http://mathworld.wolfram.com/LeastSquaresFittingPerpendicularOffsets.html

Examples

Run this code
data(mscdata)
plot.year(mscdata,id=2100630)
plot.year(mscdata,id=1108447)
newdata <- dathomog(2100630,1108447,mscdata)
plot.year(newdata)
message("This is a rather poor example, since the two stations are")
message("nowhere near each other")

Run the code above in your browser using DataLab