Time Series and Signal Interpolation and Alignment

DESCRIPTION:

Align or interpolate a time series, bdTimeSeries, signal, or bdSignalSeries to new positions.

USAGE:

align(x, pos, how="NA", error.how="NA", localzone=F, matchtol=0, by, 
      k.by=1, week.align=NULL, holidays=timeDate()) 

REQUIRED ARGUMENTS:

x
object to be aligned or interpolated.

OPTIONAL ARGUMENTS:

pos
new positions to align or interpolate it to (either pos or by is required).
how
how to treat unmatched positions, one of: "NA" - insert a row of NA; "drop" - drop that position entirely; "nearest" - use the row with the nearest position; "before" - use the data from the row whose position is just before the unmatched position; "after" - use the data from the row whose position is just after the unmatched position; "interp" - interpolate linearly between "before" and "after".
error.how
what to do when there is an out of bounds error (can occur when how is "before", "after", or "interp"), one of: "NA" - insert a row of NA; "drop" - drop that position entirely; "nearest" - use the row with the nearest position.
localzone
if T ( x must be a calendar-based time series or bdTimeSeries), align by matching/interpolating with both x and pos in their local time zones, instead of with the absolute GMT times.
matchtol
tolerance for matching positions. Positions which match within matchtol will not invoke any of the how argument methods.
by
if pos is missing and by is supplied for aligning a calendar-based time series or bdTimeSeries, new positions are generated as a regular time/date sequence using by, k.by, week.align, and holidays. by gives the spacing between successive values in the sequence. This can be a timeSpan, bdTimeSpan, timeRelative, or numeric value, in which case k.by is ignored. Alternatively, it can be one of the following character strings: "milliseconds", "seconds", "minutes", "hours", "days", "weekdays", "bizdays", "weeks", "months", "quarters", or "years", giving the time units of intervals between values in the sequence.
k.by
non-zero integer giving the width of the interval between consecutive values in the sequence in terms of the units given in by. Ignored if by is not a character string or if pos is given.
week.align
if not NULL and by is "weeks", you can supply a character string (or a number, 0 to 6 with 0 being Sunday) to specify a weekday to align to. The character string must be sufficient to make a unique case-insensitive match to the strings in options("time.day.name"). Ignored if by is not a character string or pos is given.
holidays
holidays for business day sequences (ignored if by is not a character string or pos is given).

VALUE:

a new time series, bdTimeSeries, signal, or bdSignalSeries whose positions are the passed-in positions or positions generated from by, k.by etc. (or possibly a subset if how or error.how is "drop") and whose rows are derived from x as specified in the arguments.

DETAILS:

If either x or pos (or the generated sequence) has zero length, a zero-length series will be returned.

SEE ALSO:

, , , .

EXAMPLES:

a <- signalSeries(pos=1:10, data=data.frame(a = 11:20, b = 5 * (1:10))) 
align(a, c(.2, 3, 7.8, 12), how = "interp", error.how = "nearest") 
a <- timeSeries(pos=as(1:10, "timeDate"), 
                data=data.frame(a = 11:20, b = 5 * (1:10))) 
alpos <- as(c(.2, 3, 7.8, 12), "timeDate") 
alpos@time.zone <- "JST" 
positions(a)@time.zone <- "PST" 
align(a, alpos, matchtol = 1, localzone = T) 
align(a, matchtol=1, localzone=T, by="days", k.by=2)