1.3.merge.data.pems {pems.utils} | R Documentation |
Various pems.utils functions to merge data of different types.
#basic alignment align(data1, data2, n = 0, ...) #alignment based on correlation cAlign(form, data1 = NULL, data2 = NULL, ...) #alignment based on time.stamp tAlign(form, data1, data2 = NULL, order=TRUE, ...) #historical findLinearOffset(x = NULL, y = NULL, offset.range = NULL)
data1, data2 |
( |
n |
( |
... |
(An other arguments) May be passed on but are typically ignored. See Notes. |
form |
( |
order |
( |
x, y |
(Required objects, various classes) For |
offset.range |
(Numeric) For |
The align
function accepts two pems
objects,
data.frame
, etc, and returns a single dataset (as
a pems
object) of the aligned data. An extra argument,
n
, may be supplied to offset the starting row of the
second data set relative to the first. It is intended to be
used in the form:
aligned.data <- align(data1, data2)
#aligned row 1-to-1
aligned.data <- align(data1, data2, 3)
#row 3-to-1, etc
The cAlign
function accepts a formula and up to two data
sets and returns a single data set (as a pems
object) of
correlation aligned data. This uses the best fit linear offset
correlation for the elements identifed in the formula term.
It is intended to be used in the form:
aligned.data <- cAlign(name1~name2, data1, data2)
The tAlign
function accepts a formula and two data sets
and returns a single data set (as a pems
object) of the
time stamp aligned data. This is this done by matching entries
in the elements identifed in the formula term.
It is intended to be used in the form:
aligned.data <- tAlign(name1~name2, data1, data2)
Historical functions:
findLinearOffset
is historical code.
align
, cAlign
, tAlign
, etc all return a
single object of pem
class containing the aligned data
from data1
and data2
.
findLinearOffset
returns the best fit offset for y
relative to x
.
These functions are under revision and need to be handled with care.
cAlign
: By default cAlign
generates an alignment
plot and returns a pems
object of aligned data. But it
also allows several hidden arguments to refine outputs, the
logicals plot
, offset
and pems
, which turn
off/on plot, offset and pems reporting individually, and
output = c("plot", "offset", "pems")
or combinations thereof
also provides a single argument alternative.
bindPEMS
: The historical function bindPEMS
has
been superceded by align
, cAlign
options.
findLinearOffset
: findLinearOffset
is currently
retained but will most likely be removed from future versions of
pems.utils
.
The call cAlign(x, y, output = "offset")
is equivalent to
findLinearOffset(x, y)
.
Karl Ropkins
align
uses the dplyr
function full_join
.
cAlign
function uses the stats
function ccf
.
tAlign
uses the dplyr
function full_join
.
See also: cbind
for standard column binding in R
;
dplyr
for full_join
.
########### ##example 1 ########### ##data vector alignment #make two offset ranges temp <- rnorm(500) x <- temp[25:300] y <- temp[10:200] #plot pre-alignment data plot(x, type="l"); lines(y, col="blue", lty=2) #estimated offset findLinearOffset(x,y) #[1] -15 #applying linear offset ans <- align(x, y, findLinearOffset(x,y)) names(ans) <- c("x", "y") #plot post-alignment data plot(ans$x, type="l"); lines(ans$y, col="blue", lty=2) #shortcut using cAlign ## Not run: plot(x, type="l"); lines(y, col="blue", lty=2) ans <- cAlign(x~y) plot(ans$x, type="l"); lines(ans$y, col="blue", lty=2) ## End(Not run) ########### ##example 2 ########### ##aligning and merging data sets ##(pems object example) #make some offset data p1 <- pems.1[101:200, 1:5] p2 <- pems.1[103:350, 1:3] #correlation alignment using ccf ans <- cAlign(~conc.co, p1, p2) #this aligns by comparing p1$conc.co and p2$conc.co #and aligning at point of best linear regression fit ## Not run: #compare: cAlign(~conc.co, p2, p1) cAlign(conc.co2~conc.co, p1, p2) #(aligns using p1$conc.co2 and p2$conc.co) cAlign(conc.co2~conc.co, p1) #(realigns just conc.co within p1 based on best fit # with conc.co2 and returns as output ans) #time stamp alignment tAlign(~time.stamp, p1, p2) #this aligns by pairing elements in p1$time.stamp #and p2$time.stamp #(if time stamps have different names # tAlign(time1~time2, p1, p2), the time stamp name # from p1 would be retained when merging p1$time1 # and p2$time2, generating [output]$time1) ## End(Not run)